Giving an app fine-grained access to certain device features is a reoccurring theme in a mobile application. Luckily Tabris.js offers a rich set of APIs to handle these types of runtime permissions. While the Tabris.js API is feature-rich, sometimes all that is required is to perform an action only when certain permission is available.
For these common use cases Tabris.js offers the convenience API
permissions.withAuthorization(). To use it, you merely need to give your desired permission and to provide a callback which will be executed when the the permission has been granted:
() => camera.active = true,
() => console.log('"camera" permission is required.'),
(e) => console.error(e));
In the above example, we require the
'camera' permission and activate the camera when the permission is given.
As you can see, the entire process of handling permissions has been greatly simplified.