Permission Manager¶
The Permission manager purpose is control the requests of permissions. By default the SDK requests all necessary permissions immediately when it starts, or when the module that need a specific permission for itself starts, but this is not always appropriate. The solution for the user experience problem of having permissions requested on wrong time, is the Permission Manager.
Note
Permission Manager singleton is only available after Pointr is in RUNNING state.
Controlling when permissions are requested¶
iOS:
extension ViewController: PTRPermissionManagerDelegate {
func setPermissionManagerDelegate() {
Pointr.shared.permissionManager?.delegate = self
}
// Example for not allowing the automatic request by the SDK for location while in use
func permissionManagerShouldRequestLocationAuthorizationPermissionForWhenInUse(_ permissionManager: PTRPermissionManager) -> Bool {
return false
}
// Example for adding custom logic just before camera permission is asked (AR) by the SDK
func permissionManagerShouldRequestCameraAuthorizationPermission(_ permissionManager: PTRPermissionManager) -> Bool {
// Do something before the permission is asked for.
return true
}
}
Android:
Pointr.getPointr()?.permissionManager?.shouldRequestLocationPermissionForAlways = false
Getting notified about permission changes¶
iOS:
extension ViewController: PTRPermissionManagerListener {
func listenToPermissionChanges() {
Pointr.shared.permissionManager?.addListener(self)
}
// Location authorization has changed
func permissionManager(_ permissionManager: PTRPermissionManager, didUpdateLocationAuthorizationStatus status: CLAuthorizationStatus, oldStatus: CLAuthorizationStatus) {
// Client's code
}
}
Android:
Pointr.getPointr()?.permissionManager?.addListener(object:PermissionManager.Listener{
override fun onBluetoothServiceStateUpdate(state: BluetoothServiceState) {
// Do something when bluetooth service state changed
}
override fun onLocationServiceStateUpdate(isEnabled: Boolean) {
// Do something when location service state changed
}
override fun onBluetoothPermissionGranted(state: BluetoothPermissionState) {
// Do something when bluetooth permission state changed
}
override fun onLocationPermissionGranted(state: LocationPermissionState) {
// Do something when location permission state changed
}
override fun onCameraPermissionGranted() {
// Do something when camera permission is granted
}
})
Checking permission status¶
iOS:
extension ViewController {
func checkPermissionStatus() {
let locationServicesEnabled = Pointr.shared.permissionManager?.isLocationServicesEnabled
}
}
Android:
//checking for Bluetooth
if (Pointr.getPointr()?.permissionManager?.isBluetoothServicesEnabled == true) {
// Do something
}
//checking for Location
if (Pointr.getPointr()?.permissionManager?.hasLocationPermissionWhileInUse == true) {
// Do something
}
Requesting permission manually¶
iOS:
extension ViewController {
func requestPermission() {
Pointr.shared.permissionManager?.requestCameraAuthorizationPermission()
}
}
Android:
Pointr.getPointr()?.requestCameraPermission(activity, requestCode)
Last update: August 26, 2022