Initializing the SDK
You must initialize the SDK before your app can consume its methods. To initialize, set the required configurations through a ZCRMSDKConfigs object and pass it to the initSDK method in the ZCRMSDKClient object as follows.
try ZCRMSDKClient.shared.initSDK(window: UIwindow, appConfiguration : ZCRMSDKConfigs ) throws
Parameters
window : Specify your window object that dispatches events to your views.
appConfiguration : Set the required appConfiguration properties and pass the object.
If the user is not logged in, a login screen will be prompted during the SDK initialization. Based on the result of the login, the appropriate callback method will be triggered.
Only after the successful initialization of the SDK, further methods can be invoked as intended.
SDK Configuration object
The ZCRMSDKConfigs class has the following configuration properties and methods.
Properties
Property | Datatype | Description |
---|---|---|
clientId | String | The Unique identifier of your app |
clientSecret | String | The client secret is a secret known only to the application and the authentication server |
redirectURLScheme | String | The URL to which the app should be redirected after the authentication is complete |
apiVersion | String | Version of the CRM API |
showSignUp | String | Based on this value, Sign up page will be shown |
accountsURL | String | The URL for redirecting the app to the account's page for logging in |
oauthScopes | String | The scopes required to access CRM APIs from your project |
apiBaseURL | String | The base URL to be used when calling a CRM API |
accessType | AccessType | The environment in which your application will be running. The environments available are production, development and sandbox |
countryDomain | CountryDomain | The top-level domain of the data Server. The possible values are com.au, com.cn, com, eu and in |
portalId | String | The PortalID of your CRM project |
groupIdentifier | String | The identifier of your app to share the database container within the app groups |
appType | appType | The category to which your app belongs. The possible values are zcrm, zvcrm and zcrmcp |
Methods
validateProperties
public func validateProperties() throws
This method checks whether you have given all the mandatory properties according to the appType and throws error in compile-time if any property is null.
Builder Class
This class helps developers to build the configuration properties (ZCRMConfigs object). You can set the required properties through this class and pass the ZCRMConfigs object obtained through build method to initSDK, so the properties change would be reflected throughout the entire app.
Initialization
Builder class has to be initialized before its methods are consumed by the app. Only after the successful initialization of the class, further methods can be invoked as intended.
init method for .zcrm
public init ( clientId : String, clientSecret : String, redirectURL : String, oauthScopes : [ String ] )
This method initializes the builder class and is used if the appType is .zcrm.
Parameters
clientId : Id of the client.
clientSecret : A secret obtained during client creation.
redirectURL : Unique identifier to redirect to the app after successful authentication.
oauthScopes : Scopes required to hit the APIs.
init method for .zvcrm, .zcrmcp
public convenience init ( clientId : String, clientSecret : String, redirectURL : String, oauthScopes : [ String ], portalId : String )
This method initializes the builder class and is used if the appType is .zvcrm and .zcrmcp.
Parameters
clientId : Id of the client.
clientSecret : A secret obtained during client creation.
redirectURL : Unique identifier to redirect to the app after successful authentication.
oauthScopes : Scopes required to hit the APIs.
portalId : The portalID of the client.
Apptype Bigin is not supported.
Methods
The methods to configure properties for the builder class are mentioned below.
ZCRMSDKConfigs.Builder() .setAPPType( _ apptype : AppType ) -> Builder .setShowSignUp( _ showSignUp : Bool ) -> Builder .setAccountsURL( _ accountsURL : String) -> Builder .setAPIBaseURL( _ baseURL : String ) -> Builder .setAccessType( _ accessType : AccessType ) -> Builder .setCountryDomain( _ countryDomain : CountryDomain ) -> Builder .setGroupIdentifier( _ identifier : String ) -> Builder .build() throws -> ZCRMSDKConfigs
Logging In
The below snippet shows the login page to the user if they have not logged in.
public func showLogin(completion: @escaping ( ZCRMError? ) -> ()) )
Returns an error if the login was unsuccessful or returns nil if the user has already logged in.
Parameters
completion: The completion block is passed with the error value or nil based on the login status.
Logging Out
To log users out from Zoho CRM on your app, use the following code snippet.
public func logout(completion: @escaping (ZCRMError?) -> ())
Returns an error if the logout was unsuccessful.
Parameters
completion: The completion block is passed with the error value, if the logout was unsuccessful.
Utility Functions
The ZCRMSDKClient class also provides certain utility functions that you can use appropriately in your client app logic.
public func isUserSignedIn() - Returns the boolean 'true' when the user is signed in already. Else, returns 'false'.
public func enableDBCaching() - Enables the caching of meta-data API responses in the local SQLite instance of the app. Any entity that comes under the Setup screen of Zoho CRM (like organization, users, modules, layouts and so on) is considered meta-data.
public func disableDBCaching() throws - This method clears the existing database cache and disables the caching of API responses.
public static func getCurrentUser( completion : @escaping( Result.DataResponse< ZCRMUser, APIResponse > ) -> () ) - Returns the current user from the org who has signed in. This method fetches the response from cache.
Parameters:
completion : The completion block is passed with a data response from ZCRMUser API.public static func getCurrentUserFromServer( completion : @escaping( Result.DataResponse< ZCRMUser, APIResponse > ) -> () ) - Returns the current user from the org who has signed in. This method fetches the response from the server.
Parameters:
completion : The completion block is passed with a data response from ZCRMUser API.public func changeMinLogLevel( _ minLogLevel : LogLevels ) - To change the logging level of the messages using the predefined level integers.
The following are the Log levels and their respective integers.byDefault - 0
info - 1
debug - 2
error - 3
fault - 4