我正在使用React Native版本42并请求如下权限。但在允许或拒绝权限后,我在控制台中看不到状态。根据文档https://facebook.github.io/react-native/docs/permissionsandroid.html他们说我们可以在控制台中看到状态。有谁能帮我做错事吗?我想打印已授予的状态,但行本身没有被调用。
componentDidMount() {
this.requestPermissions();
}
async requestPermissions() {
try {
const granted = await PermissionsAndroid.requestMultiple([PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE, PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE])
console.log("permissions status: " +JSON.stringify(granted));
} catch (err) {
console.warn(err)
}
}
最佳答案
permissionandroid.requestmultiple返回具有权限状态的承诺。像这样试试
PermissionsAndroid.requestMultiple([PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE, PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE]).then((result) => {
console.log('result', result);
})
关于android - React Native Permissions不打印状态,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42935559/