This guide explains how application permissions can be managed in Smartface.
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.
Permission managements should be developed OS specific in the applications.
How it Works ?
Smartface iOS Frameworks handles permissions automatically for the user. Developer does not need to handle permission management. For example, lets open GPS sensor of the device shown as below;
Here is the screenshot when the code is executed;
Android 4.0+ - 6.0 Versions
Before marshmallow version, permissions are defined in AndroidManifest.xml. User can grant all permission while installing the application. In android M still user need to request the permission from manifest. Since android M addition to manifest permissions, from code sensitive permission checks must be done
Android Manifest file can be reachable under the path config/Android in the workspace.
Here is a screenshot of permission page while installing the application;
When Android Marshmallow is released, permission system of Android is totally changed. Permissions are given while using the application like iOS systems.
Table in the below shows the functioanlity and their required permissions;
This function checks if one of the dangerous permissions is granted at beginning or not. For android versions earlier than 6.0, it will return value exists in manifest or not. For permissions in same category with one of the permissions is approved earlier, checking will return as it is not required to request for the same category permission.
Permission name can be a value for name of the permission.
The example below assuming READ_CALENDAR is;
With Application.requestPermissions function, Android System Dialog will appear to ask for permission grant by user for dangerous(privacy) permissions. This function accepts array of strings similar to checkPermission function. In the background this function checks for permissions then fires Application.onRequestPermissionsResult event.
Later when Application.onRequestPermissionsResult event is called, values are matching in same order as given array in permissionNames parameter.
Displayed confirmation dialog strings, localisations and customisations cannot be made by framework, it is managed by OS.
This event is called after Application.requestPermissions function. This event is fired asynchronous way, there is no way to make sure which request is answered.
There will be only one onRequestPermissionsResult event in whole application. So for multiple requests, it should be handled per requestCode.
Or it is possible to write a generic handler for all permissions as below;
This method checks for a permission is shown before to user and the program is about to request the same permission again.
permissions.js is a library which is written by Smartface to make permission management easier.
checkPermissionfunction checks & requests permissions if required with a callback. It is possible to state a rationale (reason) why those permissions are required
applyPermissionfunction is same as
How to Use ?
List of Permission Functions;
Smf-js-libs is a asynchronous library. It's using error first pattern.
You need to download smf-js-libs repository and place these files into scripts folder of your workspace. After that, include permissions.js into app.js file shown as below;
After including , you can use predefined global methods to grant access of permissions. Here is an example of location permission for GPS as below;
After the app is started permission dialog will shown to user as below;