我在使用Expo开发的React Native应用程序中使用了镜像拾取器。当尝试访问requestMediaLibraryPermissionsAsync函数时,我得到了以下错误:
Cannot read property 'requestMediaLibraryPermissionsAsync' of undefined
字符串
相关编码:
const pickImage = async () => {
const {status} = await ImagePicker.requestMediaLibraryPermissionsAsync()
if (status !== 'granted') {
alert('Sorry, we need camera roll permissions to make this work!')
return
}
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
})
if (!result.cancelled) {
const source = {uri: result.uri}
uploadImage(source.uri)
}
}
型
我已经确保导入ImagePicker:
import * as ImagePicker from 'expo-image-picker';
型
项目配置:
expo-env-info 1.0.5 environment info:
System:
OS: macOS 13.5.1
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.17.1 - /usr/local/bin/node
npm: 8.19.4 - ~/node_modules/.bin/npm
Watchman: 2023.09.04.00 - /opt/homebrew/bin/watchman
IDEs:
Android Studio: 2022.3 AI-223.8836.35.2231.10671973
Xcode: /undefined - /usr/bin/xcodebuild
npmPackages:
expo: ~49.0.8 => 49.0.9
metro: ^0.79.0 => 0.79.0
react: 18.2.0 => 18.2.0
react-native: 0.72.4 => 0.72.4
npmGlobalPackages:
eas-cli: 5.2.0
expo-cli: 6.3.10
Expo Workflow: managed
型
到目前为止我尝试过的:
- 请检查是否正确安装了图像拾取器。
- 已确保我正在使用ImagePicker的正确导入语句。
- 已重新启动Expo客户端并清除了该高速缓存。
我想做的是:
- 确保当我点击个人资料图像上的笔图标时,它会打开我的手机媒体库以上传新图片。
有什么想法可能导致这个问题以及如何解决它?
1条答案
按热度按时间b91juud31#
我遇到了同样的问题,我通过动态导入解决了它,比如:
import { launchImageLibraryAsync,useMediaLibraryOptions,useCameraOptions,} from“图像拾取器”;