代码拉取完成,页面将自动刷新
permissions check of ios and android;
Camera、PhotoLibrary、Location、Bluetooth、Microphone are available
openSettings is for user to open setting page, and change permissions
npm install react-native-check-permissions
import {
checkMicrophone,
requestMicrophone,
checkCamera,
requestCamera,
requestPhotoLibrary,
openLimitedPhotoLibraryPicker,
openSettings,
requestMediaLibrary,
requestCoreLocation,
requestBluetooth
} from 'react-native-check-permissions';
// ...
<Button title={'设置'} onPress={() => {
openSettings().then(res => {
console.log(res);
// alert(res);
})
}}/>
<Button title={'麦克风'} onPress={() => {
requestMicrophone().then(res => {
this.showResult(res);
})
}}/>
<Button title={'相机'} onPress={() => {
requestCamera().then(res => {
this.showResult(res);
})
}}/>
<Button title={'相册'} onPress={() => {
requestPhotoLibrary().then(res => {
this.showResult(res);
})
}}/>
<Button title={'打开有限的相册'} onPress={() => {
openLimitedPhotoLibraryPicker().then(res => {
this.showResult(res);
}).catch(e => {
console.log(e.message);
})
}}/>
<Button title={'多媒体'} onPress={() => {
requestMediaLibrary().then(res => {
this.showResult(res);
}).catch(e => {
console.log(e.message);
})
}}/>
<Button title={'位置'} onPress={() => {
requestCoreLocation().then(res => {
this.showResult(res);
}).catch(e => {
console.log(e.message);
})
}}/>
<Button title={'蓝牙'} onPress={() => {
requestBluetooth().then(res => {
this.showResult(res);
}).catch(e => {
console.log(e.message);
})
}}/>
//..
showResult = (res: any) => {
let {status} = res;
switch (status) {
case 0:
// 不可用
break;
case 1:
// 未定
break;
case 2:
// 受限制的
break;
case 3:
// 拒绝
Alert.alert('提示', '无权限,请打开设置!', [{text: '取消'}, {
text: '设置', onPress: () => {
openSettings().then(res => {
});
}
}])
break;
case 4:
// 已认证
break;
case 5:
// 有限的
break;
default:
break;
}
this.setState({
result: status
})
}
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。