Handling permissions
react-native-zendrive provides permissions module to deal with various permissions that the SDK requires.
Location
Check access to location
Use the following code snippet check whether SDK has all the needed access to location.
Zendrive.permissions()
.check('location')
.then(hasAccess => {
if (hasAccess) {
console.log('location access granted');
} else {
// request access
}
});in android, the module will check granted access for android.permission.ACCESS_FINE_LOCATION and android.permission.ACCESS_BACKGROUND_LOCATION
in iOS, the module will check 'always allow' granted access for location.
Request access to location
Use the following code snippet to request access to location. Note that here we are using async/await to simplify code
const hasAccess = await Zendrive.permissions().request('location');
if (hasAccess) {
// user granted access, continue with your business logic
} else {
// user has denied, show a proper error message and provide call to action to open settings
await Zendrive.permissions().openSettings();
}In iOS once the user denies the location access, only way to enable is from settings. Similarly in android, if the users denies with never ask again checked, only way to enable is from application settings. Use openSettings method in permissions module to take the user to application settings.
Motion
Check access to motion
Use the following code snippet check whether SDK has all the needed access to motion.
Zendrive.permissions()
.check('motion')
.then(hasAccess => {
if (hasAccess) {
console.log('motion access granted');
} else {
// request access
}
});in android, the module will check granted access for android.permission.ACTIVITY_RECOGNITION
in iOS >= 11, the module will check 'authorized' granted access for motion equivalent to CMMotionActivityManager.authorizationStatus()
Request access to motion
This is not required in iOS, SDK will automatically prompt for motion usage access to user when required. We need to ensure that 'NSMotionUsageDescription' is provided in Info.plist
Use the following code snippet to request access to motion. Note that here we are using async/await to simplify code
const hasAccess = await Zendrive.permissions().request('motion');
if (hasAccess) {
// user granted access, continue with your business logic
} else {
// user has denied, show a proper error message and provide call to action to open settings
await Zendrive.permissions().openSettings();
}In android, if the users denies with never ask again checked, only way to enable is from application settings. Use openSettings method in permissions module to take the user to application settings.
Overlay
Overlay permission is applicable to android only, it is no-op in iOS.
Check access to overlay
Use the following code snippet check whether SDK has all the needed access to overlay.
Zendrive.permissions()
.check('overlay')
.then(hasAccess => {
if (hasAccess) {
console.log('overlay access granted');
} else {
// request access
}
});the module will check granted access for android.permission.SYSTEM_ALERT_WINDOW
Request access to overlay
Use the following code snippet to request overlay access. Note that here we are using async/await to simplify code
const hasAccess = await Zendrive.permissions().request('overlay');
if (hasAccess) {
// user granted access, continue with your business logic
} else {
// user has not enabled draw overlay setting, show a proper error message and provide call to action to open settings
await Zendrive.permissions().openSettings();
}This code snippet will take user directly to draw overlay permission screen in app settings, where they can choose to enable or disable permission. When they come back to app screen again the promise will resolve to true/false depending upon the action taken in permission screen.