MobbID Cordova: Initialization
Initialization
First of all, the plugin will not be available until the Cordova deviceready event triggers. It is strongly recommended to initialize MobbID Cordova plugin as follows:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
// Here goes MobbIdAPI initialization code.
}
If you are using Ionic and Angular, Platform.ready() method could be used:
import { Platform } from "@ionic/angular";
class SomeComponent {
constructor(private platform: Platform) {
this.platform.ready().then(() => {
// Here goes MobbIdAPI initialization code.
});
}
}
Obtaining the authorization token
The first steps that should be performed is obtain the authorization token in order to initialize the MobbIdApi.
For that, need and API Key, an Application ID and a Server URL that will be provided by Mobbeel.
This api request can be done in several ways. For example:
- Using a curl command:
curl -X GET "${serverUrl}/api/v7/authorization" -H "accept: application/json" -H "apiKey: ${apiKey}" -H "applicationId: ${applicationId}"
- Using a fetch request:
fetch(`${serverUrl}/api/v7/authorization`, {
method: "GET",
headers: {
apiKey: apiKey,
applicationId: applicationId,
},
});
The response will contain the authorization token that will be used to initialize the MobbIdApi.
Initializing the MobbIdApi
This method initializes the SDK with the provided parameters and sets up the environment for further operations.
MobbIdApi.initSdk(
successCallback: () => void,
errorCallback: (error: string) => void,
applicationId: string,
autToken: string
serverUrl: string
)
success and failure methods are callbacks that will be called in case of success or failure respectively.
Once the success callback of MobbIdApi.initSdk is called, MobbIdAPI is ready to be used.
