Initialize the Misuse API by creating Identity and PermissionManager objects, then pass them to AppMisuseManager.
import IMSAppMisuse
import IMSInterfaces
import IMSPermissions
import IMSBluetooth
let identity = Identity(apiKey: apiKey,externalReferenceID: userId)
let permissionManager = PermissionManager()
permissionManager.addPermissionProvider(CLLocationManager(), isRequired: true)
permissionManager.addPermissionProvider(CMMotionActivityManager(), isRequired: true)
// Add this, if app requires bluetooth permissions for trip detection
permissionManager.addPermissionProvider(BluetoothPermissionProvider(), isRequired: true)
// Servertype can be used based on two environments (.uat or .prod)
let serverType = .uat
let appMisuseService = AppMisuseManager(identity: identity,permissionManageable: permissionManager,serverType: serverType))
Calling Misuse API
There are a number of API's available depending on the service you require; choose and call the appropriate one accordingly. The serverType can be .uat or .prod based on the deployment environment.
Enabling App misuse API
This API enables the Misuse API Service.
iOS SDK scheduler
Call the app misuse scheduler to send the event type every hour by calling AppMisuseManager.enableAppMisuse()
Ensure to call the mentioned API within application(_:didFinishLaunchingWithOptions:) of app life cycle and register the scheduler key in the info.plist file for registering the scheduler.
appMisuseService.sendAppMisuseEvent(eventType: .login, serverType: .prod) { result in
switch result {
case .success:
// successful call
case .failure(let error):
// failed with \(error)
}
}
AppMisuseManager.sendLoginEvent(context)
Misuse Logout API
This API sends AppMisuse information on Logout.
Here's an example.
appMisuseService.sendAppMisuseEvent(eventType: .logout, serverType: .prod) { result in
switch result {
case .success:
// successful call
case .failure(let error):
// failed with \(error)
}
}
AppMisuseManager.sendLogoutEvent(context)
Misuse User App Launch API
This API sends AppMisuse information on User Launch.
Here's an example.
appMisuseService.sendAppMisuseEvent(eventType: .userAppLaunch, serverType: .prod) { result in
switch result {
case .success:
// successful call
case .failure(let error):
// failed with \(error)
}
}