【发布时间】:2018-10-23 10:44:00
【问题描述】:
我正在使用create-react-native-app,但我在尝试从相机胶卷中获取图像时遇到了权限问题。
当我调用方法时:ImagePicker.launchImageLibraryAsync,我得到错误:Missing camera roll permission.
import { ImagePicker } from 'expo';
export const getImageFromLibrary = () => ({
type: GET_IMAGE_FROM_LIBRARY,
promise: () => ImagePicker.launchImageLibraryAsync({
height: '100px',
width: '100px',
base64: true
})
});
错误:Missing camera roll permission. 表明我的应用没有权限,因此我创建了另一个按钮来请求权限。
import { Permissions } from 'expo';
<Button
onPress={() =>
Permissions.getAsync(Permissions.CAMERA_ROLL)
.then(console.log)
}
><Text>get permission</Text></Button>
但是当我点击这个按钮时,console.log() 方法返回:{status: "granted", expires: "never"}。
这意味着授予的权限不会过期。但是从库中获取图像的调用仍然因为没有权限而被拒绝。
【问题讨论】:
-
如果您有最新版本,请尝试回滚到版本
24.0.3。我认为这在他们的图书馆中仍然是一个悬而未决的问题。 -
感谢您的回复。我将 expo 的版本更改为并删除了
node_modules文件夹并运行了npm install。不幸的是,这也不起作用。命令Permissions.getAsync(Permissions.CAMERA_ROLL)现在返回一个包含{status: "undetermined", expires: "never"}的承诺。 -
降级后不需要请求许可。我已就此向世博会团队询问:forums.expo.io/t/…
-
这并不能解决我的问题。我已按照建议降级到世博会版本“24.0.3”。然后我运行命令
watchman watch-del-all && rm -rf node_modules && npm install && yarn cache clean。但即使重新启动 Expo XDE 和 iphone 模拟器,问题仍然存在。
标签: react-native expo create-react-native-app camera-roll