ReactNative调取摄像头拍照和访问图库,使用react-native-image-picker

       关于ReactNative在调用图库和摄像头时进行选择的情况可以根据Github上的说明实现,本人已经测试过,是正常的,有兴趣的可以去看看:https://github.com/react-native-community/react-native-image-picker

        我要实现的只是类似于QQ那样点击聊天页面的图库和相机分别调取,但是在使用时遇到了下面的错误:

出错原因是因为我在设置options时将其设为了null:

_openImage=()=>{
        const options = null;
        ImagePicker.launchImageLibrary(options,(response)=>{
            console.log('Response = ', response);
            this.setState({
                avatarSource:response.uri
            })
        });
    }

找了好久解决办法发现没有人遇到这个问题,试了几次后发现不能将其设为null,我改为下面的:

_openImage=()=>{
        const options = {};
        ImagePicker.launchImageLibrary(options,(response)=>{
            console.log('Response = ', response);
            this.setState({
                avatarSource:response.uri
            })
        });
    }

错误消失,可以正常访问图库,由于是模拟器,好像没有相机,所以我只试了图库。

猜你喜欢

转载自blog.csdn.net/weixin_44501354/article/details/88393038