TypeError: 无法读取 null 的属性 ‘launchImageLibrary’

huangapple go评论51阅读模式
英文:

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.

&lt;Button
    onPress={() =&gt;
      ImagePicker.launchImageLibrary(
       {
        mediaType: &#39;photo&#39;,
        includeBase64: false,
        maxHeight: 200,
        maxWidth: 200,
       },
        response =&gt; {
           console.log(response);
           setPhoto(response);
          },
        )
     }
       title=&quot;Select Image&quot;
/&gt;

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 &#39;react-native-image-picker&#39;;
// import {launchImageLibrary} from &#39;react-native-image-picker&#39;;

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.

huangapple
  • 本文由 发表于 2023年6月19日 01:05:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76501686.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定