react-native-image-picker在IOS上总是返回”Can’t find variable:response”的错误?

狄高畅
2023-12-01

环境:
react-native: 0.41.2
react-native-image-picker: 0.26.2
xcode 8.2.1
iphone 6

根据官方教程(https://github.com/marcshilling/react-native-image-picker)写例子,结果就栽了跟头。图库能够正常打开,但是选择后总是返回”Can’t find variable:response”错误;进一步测试,就算点取消按钮也是返回该错误;接着将回调函数的response参数重命名为res,还是得到该错误。说明我的回调函数根本没执行,直接卡在模块内部了,由于时间关系不打算继续深究模块源码,于是打算绕过去。既然ImagePicker只是对ImagePickerManager做一层封装,那么直接引用ImagePickerManager试试看呢,结果问题就解决了。

以下为部分源码:

import {NativeModules} from 'react-native';
const { ImagePickerManager } = NativeModules;
//...(无关代码省略)
        var options = {
          title: '选择图片',
          takePhotoButtonTitle:"拍照",
          chooseFromLibraryButtonTitle:"从图库选择",
          cancelButtonTitle:"取消",
          mediaType:"photo"
        };
        ImagePickerManager.showImagePicker(options, function(repsonse) {
            console.log(response);
        });
//…(无关代码省略)

转载于:https://www.cnblogs.com/pheye/p/6551644.html

 类似资料: