【问题标题】:error when launching image library in react-native在 react-native 中启动图像库时出错
【发布时间】:2021-03-14 14:11:53
【问题描述】:

所以我正在尝试使用一个名为 react-native-image-picker 的包来启动图像库:

function launchLibrary(fun) {

     let options = {
        storageOptions: {
         skipBackup: true,
         path: 'images',
      },
     };

    ImagePicker.launchImageLibrary(options, (response) => {
      console.log('Response = ', response);
      if (response.didCancel) {
        console.log('User cancelled image picker');
      } else if (response.error) {
        console.log('ImagePicker Error: ', response.error);
      } else if (response.customButton) {
        console.log('User tapped custom button: ', response.customButton);
        alert(response.customButton);
      } else {
        const source = { uri: response.uri };
        console.log(source);
        console.log('response', JSON.stringify(response));
        fun(response);
      }
    });
};

然后当函数被执行时,我得到以下响应:

 response {"errorMessage":"Activity error","errorCode":"others"}

这里出了什么问题?

【问题讨论】:

    标签: javascript react-native


    【解决方案1】:

    Google Play 商店不再接受以 SDK

    我将react-native-image-picker 更新为版本“^4.7.0”并且错误消失了,但请注意launchImageLibrary 响应现在可能包含带有图像数据的“资产”数组,而不是直接在其中包含图像数据响应对象。

    更新后,用response.assets[0].uri 替换response.uri 对我有用。

    【讨论】:

      【解决方案2】:

      我将 compileSdkVersion 和 targetSdkVersion 从 30 更改为 29 build.gradle ,取决于那个答案: https://github.com/react-native-image-picker/react-native-image-picker/issues/1600

       compileSdkVersion = 29
       targetSdkVersion = 29
      

      然后它就可以正常工作了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-04-19
        • 1970-01-01
        • 2021-11-09
        • 1970-01-01
        • 1970-01-01
        • 2018-03-05
        • 2016-06-26
        • 2018-06-18
        相关资源
        最近更新 更多