AppConnect ready API details

The 'appConnect.isReady' event

The AppConnect library begins its initialization when your app calls AppConnectCordova.initialize(). The AppConnect Cordova Plugin generates the 'appconnect.isReady' event when the AppConnect library has completed its initialization.

The isReady() method

The AppConnectCordova JavaScript interface provides an isReady() method:

AppConnectCordova.isReady()

This method indicates whether the AppConnect Cordova Plugin is ready for the app to access its other methods.

Return value: true or false

IMPORTANT: The app can access the other methods only if AppConnectCordova.isReady() returns true. If AppConnectCordova.isReady() returns false, an attempt to access another method causes the AppConnect library to throw an exception, and the app will crash.

When your app calls AppConnectCordova.initialize(), the AppConnect library begins its initialization, which concludes with the AppConnect Cordova Plugin generating the 'appconnect.isReady' event. The return value of AppConnectCordova.isReady() is false until that time. Then it will return true. The value remains true for the life of the app.

Event handler for 'appConnect.isReady' event

You are required to add an event listener to your document object for the 'appconnect.isReady' event. For example:

document.addEventListener('appconnect.isReady', this.onAppConnectIsReady, false);

The AppConnect Cordova Plugin generates the 'appconnect.isReady' event one time when the AppConnect library initialization is complete. The app starts the initialization by calling AppConnectCordova.initialize().

In your event handler:

Update the app with the current authorization status, data loss prevention policies, and configuration key-value pairs.

The information is available by calling these AppConnectCordova methods:

- AppConnectCordova.authState()
- AppConnectCordova.authMessage()
- AppConnectCordova.pasteboardPolicy()
- AppConnectCordova.openInPolicy()
- AppConnectCordova.openInWhitelist()
- AppConnectCordova.printPolicy()
- AppConnectCordova.config()

Remove the user interface indication that informed the user that the app was initializing.

Always update the app’s policies and configuration status in the event handler for the 'appconnect.isReady' event. The AppConnect Cordova Plugin generates this event when the app is launched, after the AppConnect library finishes its initialization. The AppConnect Cordova Plugin generates other events, such as the events for authorization, data loss prevention policies, and configuration, only if the status has changed. Therefore, you can always expect all these events on the first launch of the app. However, subsequent launches often result in the AppConnect Cordova Plugin generating only the 'appconnect.isReady' event.