英文:
TypeError: Cannot read property 'launchImageLibrary' of null
问题
我已经尝试了在线的所有解决方案来解决这个错误。我无法打开图像库。
<Button
onPress={() =>
ImagePicker.launchImageLibrary(
{
mediaType: 'photo',
includeBase64: false,
maxHeight: 200,
maxWidth: 200,
},
response => {
console.log(response);
setPhoto(response);
},
)
}
title="选择图像"
/>
我尝试过的解决方案:
rm -rf node_modules
npm install
cd ios
pod install
cd ..
尝试更改导入和如何调用 launchImageLibrary
:
import * as ImagePicker from 'react-native-image-picker';
// import {launchImageLibrary} from 'react-native-image-picker';
不幸的是,我没有找到一个有效的解决方案。有什么想法吗?
英文:
I have tried all the solutions online for this error. I am unable to open the image gallery.
<Button
onPress={() =>
ImagePicker.launchImageLibrary(
{
mediaType: 'photo',
includeBase64: false,
maxHeight: 200,
maxWidth: 200,
},
response => {
console.log(response);
setPhoto(response);
},
)
}
title="Select Image"
/>
Solutions I have tried:
rm -rf node_modules
npm install
cd ios
pod install
cd ..
tried to change the import and how I call the launchImageLibrary
import * as ImagePicker from 'react-native-image-picker';
// import {launchImageLibrary} from 'react-native-image-picker';
Unfortunately I have not found a solution that works? Any ideas?
答案1
得分: 1
我的临时解决方案是在升级到 Android SDK 33 后将 react-native-image-picker 升级到版本 5.0.0,并使用 react-native-permissions 包来处理 READ_MEDIA_IMAGES 权限。
英文:
My temporary solution after updating to Android SDK 33 is to upgrade react-native-image-picker to version 5.0.0 and use react-native-permissions package to handle READ_MEDIA_IMAGES permission.
答案2
得分: 0
修复方法是:
rm -rf node_modules
npm install
cd ios
pod install
cd ..
然后清理构建并重新构建应用程序。
英文:
The fix was to
rm -rf node_modules
npm install
cd ios
pod install
cd ..
Then clean the build and rebuild the app.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论