【发布时间】:2021-06-11 12:06:59
【问题描述】:
大家好,我有一个应用程序,它允许用户在任务期间拍照。
最近在第一次请求相机权限时,设备没有显示本机警报,而是推迟到我的辅助警报,如果用户在第一次尝试后拒绝或更改了他们的权限设置,则应该使用该辅助警报。
我的理解是,当第一次询问设备时,iOS 会提供类似于此的权限警报
我的info.plist有这个
<key>NSCameraUsageDescription</key>
<string>Allow access to your camera to take pictures of your dog!</string>
用户点击应用中的相机按钮时的代码(底部的解决方案)
function takePhoto() {
check(
Platform.select({
ios: PERMISSIONS.IOS.CAMERA,
android: PERMISSIONS.ANDROID.CAMERA,
})
)
.then(async (response) => {
if (response == 'unavailable') {
alert('Camera is not available on this device');
return;
}
const userId = auth().currentUser.uid;
let image = null;
const mapAPI = new MapAPI(firestore(), userId, storage);
const showSettingsAlert = (title, message) => {
Alert.alert(
title,
message,
[
{
text: translations['settings.goto'],
onPress: async () => {
Linking.openSettings();
},
},
{
text: translations['cancel'],
onPress: () => {
console.log('Cancel Pressed');
},
style: 'cancel',
},
],
{ cancelable: true }
);
};
if (response != RESULTS.GRANTED) {
showSettingsAlert(
translations['permissions.cameratitle'],
translations['permissions.cameradesc']
);
return;
}
我一直在努力解决这个问题,感谢任何帮助。谢谢!
【问题讨论】:
标签: android ios react-native permissions ios-camera