React Native应用程序在打开相机时崩溃



这个程序崩溃了,因为它试图在没有使用说明的情况下访问隐私敏感数据。该应用程序的信息。plist必须包含一个NSPhotoLibraryUsageDescription键,用一个字符串值向用户解释应用程序如何使用这些数据。

我添加了:

<key>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the photo library.</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app does not require access to the microphone.</string>
<key>NSCameraUsageDescription</key>
<string>This app requires access to the camera.</string>

我已经用npm安装了react-native-image-picker

应用程序崩溃,因为它没有请求许可,我只是不明白为什么它不请求许可,因为我已经添加了必要的信息。

我正在尝试让它在离子模拟器上工作,我的机器是M1 macbook。

在使用相机或访问设备存储之前,应授予应用程序所需的权限。

react-native-permissions为iOS和Android提供了权限管理抽象API。


import { request, PERMISSIONS, RESULTS } from "react-native-permissions";
import { launchCamera } from "react-native-image-picker";
function capturePhoto() {
request(
Platform.OS === "ios" ? PERMISSIONS.IOS.CAMERA : PERMISSIONS.ANDROID.CAMERA
).then(async (result) => {
if (result === RESULTS.GRANTED) {
// Camera access permission granted, you can launch camera
const result = await launchCamera();
}
});
}