React Native module Permissions permission application

小云云
Release: 2017-12-27 10:12:17
Original
2415 people have browsed it

This article mainly introduces relevant information about the detailed examples of Permissions permission application in the React Native module. I hope this article can help everyone. Friends in need can refer to it. I hope it can help everyone.

Detailed explanation of examples of Permissions application in React Native module

Foreword

For mobile development, we know that after Android 6.0 A great upgrade has been made to the permission management. Its management method similar to IOS requires manual authorization to allow the use of the current permissions. Such a module also exists in RN development.

Processing method

A PermissionsAndroid module is provided in RN, which can access the permission model provided by Android M (that is, 6.0). There are some permissions written in AndroidManifest.xml that can be automatically obtained during installation. However, some "dangerous" permissions require a prompt box to pop up for the user to choose. This API is used in the latter case.

On devices lower than Android 6.0, permissions will be automatically obtained as long as they are written in AndroidManifest.xml. In this case, the check and request methods will always return true.


async function requestCameraPermission() { try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.CAMERA, { 'title': 'Cool Photo App Camera Permission', 'message': 'Cool Photo App needs access to your camera ' + 'so you can take awesome pictures.' } ) if (granted === PermissionsAndroid.RESULTS.GRANTED) { console.log("You can use the camera") } else { console.log("Camera permission denied") } } catch (err) { console.warn(err) } }
Copy after login

Commonly used

check(permission)

Return one promise, the final value is a Boolean value indicating whether the user has authorized it.

request(permission, rationale?)

A prompt box pops up to request a certain permission from the user. Returns a promise, the final value is a Boolean value indicating whether the user agrees to the permission application.

requestMultiple(permissions)

Request multiple permissions from the user in a pop-up box. The return value is an object, the key is the name of each permission, and the corresponding value is whether the user is authorized or not.

Related recommendations:

Detailed explanation of prop-types in React Native for attribute confirmation

Detailed explanation of communication examples between react native and webview

How to write custom modules in React Native

The above is the detailed content of React Native module Permissions permission application. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!