我试图创建一个应用程序,用户可以在按下按钮时拍照。在设置app.json上的相机权限之前,它在我的物理设备上运行得非常好,但是在设置了app.json上的权限之后,它就不能工作了。我仍然得到弹出,它要求用户的许可,但在允许使用相机,它不激活相机。当我再按下按钮的时候,它还是不起作用。
app.json
"plugins": [
[
"expo-image-picker",
{
"photosPermission": "custom photos permission",
"cameraPermission": "Allow $(PRODUCT_NAME) to open the camera",
"//": "Disables the microphone permission",
"microphonePermission": false
}
]
],
"android": {
"package":"mycamera.myapp",
"versionCode": 2,
"permissions": ["CAMERA","READ_EXTERNAL_STORAGE"],
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
}
}HomeScreen.js
const [allImage, setAllImage] = React.useState([]);
const useCamera = async () => {
const hasPermissions = await cameraPermission();
if (!hasPermissions) {
return;
}
if(allImage.length < 4){
let result = await ImagePicker.launchCameraAsync({
allowsEditing: true,
quality: 0.5,
});
if (!result.cancelled) {
const name = result.uri.split('/').pop();
let match = /\.(\w+)$/.exec(name);
let type = match ? `image/${match[1]}` : `image`;
let newFile = {
uri: result.uri,
type: type,
name: name
}
setAllImage(newFile)
setPickedImage(result.uri)
if (!pickedImage && allImage.length === 0) {
setAllImage([newFile]);
setFileName("Receipt 1")
}else {
setAllImage([...allImage, newFile]);
setFileName(fileName + ", Receipt " + (allImage.length + 1))
}
}
}
};发布于 2022-08-09 08:30:02
对于expo选择器的expo权限,如官方文档所示,您需要创建app.config、js / app.json文件并在那里添加权限。
详细步骤在主页链接-> https://github.com/expo/expo/tree/sdk-46/packages/expo-image-picker中提供。
您需要按以下方式添加权限
从官方网站获取图像权限的app.config.js实例
{
"expo": {
"plugins": [
[
"expo-image-picker",
{
"photosPermission": "custom photos permission",
"cameraPermission": "Allow $(PRODUCT_NAME) to open the camera",
"//": "Disables the microphone permission",
"microphonePermission": false
}
]
]
}
}https://stackoverflow.com/questions/73287699
复制相似问题