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

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

TypeError: Cannot read property 'launchImageLibrary' of null

问题

我已经尝试了在线的所有解决方案来解决这个错误。我无法打开图像库。

  1. <Button
  2. onPress={() =>
  3. ImagePicker.launchImageLibrary(
  4. {
  5. mediaType: 'photo',
  6. includeBase64: false,
  7. maxHeight: 200,
  8. maxWidth: 200,
  9. },
  10. response => {
  11. console.log(response);
  12. setPhoto(response);
  13. },
  14. )
  15. }
  16. title="选择图像"
  17. />

我尝试过的解决方案:

  1. rm -rf node_modules
  2. npm install
  3. cd ios
  4. pod install
  5. cd ..

尝试更改导入和如何调用 launchImageLibrary

  1. import * as ImagePicker from 'react-native-image-picker';
  2. // 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.

  1. &lt;Button
  2. onPress={() =&gt;
  3. ImagePicker.launchImageLibrary(
  4. {
  5. mediaType: &#39;photo&#39;,
  6. includeBase64: false,
  7. maxHeight: 200,
  8. maxWidth: 200,
  9. },
  10. response =&gt; {
  11. console.log(response);
  12. setPhoto(response);
  13. },
  14. )
  15. }
  16. title=&quot;Select Image&quot;
  17. /&gt;

Solutions I have tried:

  1. rm -rf node_modules
  2. npm install
  3. cd ios
  4. pod install
  5. cd ..

tried to change the import and how I call the launchImageLibrary

  1. import * as ImagePicker from &#39;react-native-image-picker&#39;;
  2. // 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

修复方法是:

  1. rm -rf node_modules
  2. npm install
  3. cd ios
  4. pod install
  5. cd ..

然后清理构建并重新构建应用程序。

英文:

The fix was to

  1. rm -rf node_modules
  2. npm install
  3. cd ios
  4. pod install
  5. 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:

确定