Print policy API details
The AppConnect Cordova Plugin provides an enumeration, an event, and methods that allow an app to handle its print policy as determined by the MobileIron server. For an overview of this feature, see Data loss prevention policies.
The ACPrintPolicy enumeration
The AppConnectCordova.ACPrintPolicy enumeration provides the possible print statuses for the app:
AppConnectCordova.prototype.ACPrintPolicy = { UNAUTHORIZED: 0, // The application may not use Print. AUTHORIZED: 1 // The application may use Print. }
The printPolicy() method
The following method returns the current status of the print policy for the app:
AppConnectCordova.printPolicy()
Return value: An AppConnectCordova.ACPrintPolicy enumeration value.
Calling printPolicy() when your app launches
When your app launches:
1. | Upon receiving the Cordova 'deviceready' event, call the method AppConnectCordova.initialize(). |
2. | Wait for the AppConnectCordova event 'appconnect.isReady' before calling the printPolicy() method. |
3. | In the event handler for the 'appconnect.isReady' event, enable or disable the app’s ability to print. Whether to enable or disable printing depends on the AppConnectCordova.ACPrintPolicy value returned from AppConnectCordova.printPolicy(). |
printPolicy() return value after updates to print policy
On any updates to the print policy while the app is running, the AppConnect Cordova Plugin generates the 'appconnect.printPolicyChangedTo' event. Subsequent calls to the AppConnectCordova.printPolicy() method returns the updated print policy.
The 'appconnect.printPolicyChangedTo' event
The AppConnect Cordova Plugin generates the 'appconnect.printPolicyChangedTo' event when the print policy changes after the plugin initialization is completed.
The event object passed to the event handler contains:
Event object properties |
Description |
newPrintPolicy |
An AppConnectCordova.ACPrintPolicy enumeration value |
Event handler for 'appConnect.printPolicyChangedTo' event
When a change has occurred to the print policy on the MobileIron server, the AppConnect Cordova Plugin:
1. | Stores the new ACPrintPolicy value so that subsequent calls to the AppConnectCordova.printPolicy() method return the updated policy. |
2. | Generates the 'appconnect.printPolicyChangedTo' event. |
You can optionally add an event listener to your document object for the 'appconnect.printPolicyChangedTo' event. For example:
document.addEventListener('appconnect.printPolicyChangedTo', this.onPrintPolicyChangedTo, false);
Add this event listener only if your app is able to print.
Your app handles the new status as follows:
New status |
App actions |
UNAUTHORIZED |
|
AUTHORIZED |
|
The AppConnectCordova.printPolicyApplied() method
After your event handler processes the information provided in the 'appconnect.printPolicyChangedTo' event, it must call this acknowledgment method:
AppConnectCordova.prototype.printPolicyApplied (policyState, message)
Your app passes the following parameters to this method:
•the AppConnectCordova.ACPolicyState value that represents the success or failure of handling the new print policy.
Pass the value APPLIED if the app successfully handled the new policy. Otherwise, pass the value ERROR. Pass the value UNSUPPORTED if your app does not support printing. If you do not implement an event handler for the 'appconnect.printPolicyChangedTo' event, the AppConnect Cordova Plugin behaves as if you passed it UNSUPPORTED.
•a string explaining the AppConnectCordova.ACPolicyState value.
Typically, you use this string to report the reason the app failed to apply the new print policy. The string is reported in the MobileIron server log files.