Users must grant permission for an app to access sensitive information, including the current location, calendar, contact information, reminders and photos. Although people appreciate the convenience of using an app that has access to this information, they also expect to have control over their privacy.
Permission management requires OS-specific development since permission structures are totally separate in iOS and Android.
Smartface iOS Framework handles permissions automatically for the user. Developer does not need to handle permission management.
import Location = require('sf-core/device/location');​Location.start(Location.Android.Priority.HIGH_ACCURACY, 1000);Location.onLocationChanged = (event: { latitude: number, longitude: number}): void => {console.log("Location latitude: " + event.latitude + " Longitude: " + event.longitude);};​
import Location = require('sf-core/device/location');​Location.start();Location.onLocationChanged = function(event) {console.log("Location latitude: " + event.latitude + " Longitude: " + event.longitude);};
In addition, there are also some convenient functions that check the status of related permission. Location permission status example like below;
import Location = require('sf-core/device/location');​//@ts-ignoreswitch (Location.ios.getAuthorizationStatus()) {//@ts-ignorecase Location.ios.authorizationStatus.Authorized:/*code block*/break;//@ts-ignorecase Location.ios.authorizationStatus.Denied:/*code block*/break;//@ts-ignorecase Location.ios.authorizationStatus.NotDetermined:/*code block*/break;default:/*code block*/}
In the JavaScript side, there are some methods which are necessary for managing permissions.
import Application = require("sf-core/application");​const CAMERA_PERMISSION_CODE: number = 1002;const CAMERA_PERMISSION = Application.Android.Permissions.CAMERA;​function getPermission(permission: string, code: number) : void {let prevPermissionRationale = Application.Android.shouldShowRequestPermissionRationale(permission);Application.android.onRequestPermissionsResult = function (e) {if (e.requestCode != code)return;​let currentPermissionRationale = Application.Android.shouldShowRequestPermissionRationale(permission);if (e.result) {console.log("GRANTED");}else if (!currentPermissionRationale) {if (prevPermissionRationale) {console.info("NEVER ASK AGAIN");}else {console.info("COULD NOT ASK");}}else {console.log("DENIED");}};​if (Application.android.checkPermission(permission)) {console.log("ALREADY GRANTED");}else {Application.android.requestPermissions(code, permission);}}
Used for permission operations. It works for android and ios. To install the extension into your workspace, visit sf-extension-utils page.
PermissionUtil.getPermission returns true always on IOS devices.
PermissionUtil.getPermission takes two arguments. First argument is a permission, second argument is a callback when triggers on permission result. To handle permission request result, pass the second parameter as a function.
import PermissionUtil = require("sf-extension-utils/lib/permission");import Contacts = require("sf-core/device/contacts");import Application = require("sf-core/application");​PermissionUtil.getPermission(Application.Android.Permissions.READ_CONTACTS,(result) => {alert("READ_CONTACTS permission result: " + result);});​module.exports = pagePermission;
The permission prompt dialogs cannot be customized or localized. They are fully managed by the operating system for security purposes.
For required permission operations, you must add permissions to config/AndroidManifest.xml on Cloud IDE.
Some features requires specific permission both iOS and Android. For example, when you want to access user's location, you need Location permission. In this section, you can find which Smartface Native Framework feature requires which permission.
Feature | Android Manifest | iOS Info.plist | Android Run-time |
​Application.byteReceived​ | READ_PHONE_STATE | ​ | READ_PHONE_STATE |
​Application.byteSent​ | READ_PHONE_STATE | ​ | READ_PHONE_STATE |
​Application.checkUpdate​ | WRITE_EXTERNAL_STORAGE | ​ | WRITE_EXTERNAL_STORAGE |
​Device.Contacts.add​ | WRITE_CONTACTS | NSContactsUsageDescription ${PRODUCT_NAME} Contact fetch | WRITE_CONTACTS |
​Device.Contacts.getAll​ | READ_CONTACTS | NSContactsUsageDescription ${PRODUCT_NAME} Contact fetch | READ_CONTACTS |
​Device.Hardware.IMEI​ | READ_PHONE_STATE | ​ | READ_PHONE_STATE |
​Device.Hardware.UID​ | READ_PHONE_STATE | ​ | READ_PHONE_STATE |
ACCESS_COARSE_LOCATION || ACCESS_FINE_LOCATION | NSLocationWhenInUseUsageDescription ${PRODUCT_NAME} WhenInUse Location | ACCESS_COARSE_LOCATION || ACCESS_FINE_LOCATION | |
READ_EXTERNAL_STORAGE | NSPhotoLibraryUsageDescription ${PRODUCT_NAME} PhotoLibrary Usage NSCameraUsageDescription ${PRODUCT_NAME} Camera Usage | READ_EXTERNAL_STORAGE | |
USE_FINGERPRINT | ​ | - | |
​IO.File 2 | READ_EXTERNAL_STORAGE | ​ | READ_EXTERNAL_STORAGE |
​Net.Http 3 | ACCESS_NETWORK_STATE | NSAppTransportSecurity NSAllowsArbitraryLoads | - |
​SpeechRecognizer.start​ | RECORD_AUDIO | NSSpeechRecognitionUsageDescription ${PRODUCT_NAME} Speech Recognition Usage NSMicrophoneUsageDescription ${PRODUCT_NAME} Microphone Usage | RECORD_AUDIO |
CAMERA | NSCameraUsageDescription $(PRODUCT_NAME) shoots contact picture | CAMERA | |
​sf-extension-smsreceiver​ | RECEIVE_SMS READ_SMS | ​ | RECEIVE_SMS READ_SMS |
​Application.call​ | CALL_PHONE | ​ | CALL_PHONE |
​Device.System.Vibrate​ | VIBRATE | ​ | VIBRATE |
​UI.MapView​ | MAPS_RECEIVE | ​ | MAPS_RECEIVE |
1 For Android, based on Provider; you can use ACCESS_COARSE_LOCATION for Location.Android.Provider.NETWORK, ACCESS_FINE_LOCATION for Location.Android.Provider.GPS and Location.Android.Provider.AUTO 2 For Android, all methods and properties under IO.File requires READ_EXTERNAL_STORAGE permission if the file is not under Path.DataDirectory. 3 For Android, all methods under Net.Http requires ACCESS_NETWORK_STATE permission.