Smartface Developer Center

Smartface Developer Center

Welcome to the Smartface Developer Hub. You'll find comprehensive guides and documentation to help you start developing and managing native iOS and Android apps with Smartface Cloud.

Get Started    

Application Permission Management

Why permissions are required ?

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.

Implementation Requirement

Permission management requires OS-specific development since permission structures are totally separate in iOS and Android.

IOS

Smartface iOS Framework handles permissions automatically for the user. Developer does not need to handle permission management.

const 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;

const Location = require('sf-core/device/location');

switch(Location.ios.getAuthorizationStatus()) {
case Location.ios.authorizationStatus.Authorized:
    /*code block*/
    break;
case Location.ios.authorizationStatus.Denied:
    /*code block*/
    break;
case Location.ios.authorizationStatus.NotDetermined:
    /*code block*/
    break;
default:
    /*code block*/
}

Android

In the JavaScript side, there are some methods which are necessary for managing permissions.

const Application = require("sf-core/application");

const CAMERA_PERMISSION_CODE = 1002;
const CAMERA_PERMISSION = Application.Android.Permissions.CAMERA;

getPermission(CAMERA_PERMISSION, CAMERA_PERMISSION_CODE);

function getPermission(permission, code) {
    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);
    }
}

PermissionUtil Extension

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.

Permission Request Result

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.

const PermissionUtil = require("sf-extension-utils").permission;
const Contacts = require("sf-core/device/contacts");
const Application = require("sf-core/application"); 

PermissionUtil.getPermission(Application.android.Permissions.READ_CONTACTS,
    function(result) {
        alert("READ_CONTACTS permission result: " + result);
    });

module.exports = pagePermission;

Permission Prompts

The permission prompt dialogs cannot be customized or localized. They are fully managed by the operating system for security purposes.

Publishing Binaries from Cloud IDE

For required permission operations, you must add permissions to config/AndroidManifest.xml on Cloud IDE.

Which permission you should use with Smartface Native Framework?

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

READ_PHONE_STATE

READ_PHONE_STATE

READ_PHONE_STATE

READ_PHONE_STATE

WRITE_EXTERNAL_STORAGE

WRITE_EXTERNAL_STORAGE

WRITE_CONTACTS

<key>NSContactsUsageDescription</key>
<string>${PRODUCT_NAME} Contact fetch</string>

WRITE_CONTACTS

READ_CONTACTS

<key>NSContactsUsageDescription</key>
<string>${PRODUCT_NAME} Contact fetch</string>

READ_CONTACTS

READ_PHONE_STATE

READ_PHONE_STATE

READ_PHONE_STATE

READ_PHONE_STATE

ACCESS_COARSE_LOCATION || ACCESS_FINE_LOCATION

<key>NSLocationWhenInUseUsageDescription</key>
<string>${PRODUCT_NAME} WhenInUse Location</string>

ACCESS_COARSE_LOCATION || ACCESS_FINE_LOCATION

READ_EXTERNAL_STORAGE

<key>NSPhotoLibraryUsageDescription</key>
<string>${PRODUCT_NAME} PhotoLibrary Usage</string>

<key>NSCameraUsageDescription</key>
<string>${PRODUCT_NAME} Camera Usage</string>

READ_EXTERNAL_STORAGE

READ_EXTERNAL_STORAGE

READ_EXTERNAL_STORAGE

ACCESS_NETWORK_STATE

<key>NSAppTransportSecurity</key>

<dict> <key>NSAllowsArbitraryLoads</key><true/>
</dict>

-

RECORD_AUDIO

<key>NSSpeechRecognitionUsageDescription</key>
<string>${PRODUCT_NAME} Speech Recognition Usage</string>

<key>NSMicrophoneUsageDescription</key>
<string>${PRODUCT_NAME} Microphone Usage</string>

RECORD_AUDIO

CAMERA

<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) shoots contact picture</string>

CAMERA

RECEIVE_SMS
READ_SMS

RECEIVE_SMS
READ_SMS

CALL_PHONE

CALL_PHONE

VIBRATE

VIBRATE

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.

Application Permission Management


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.