美文网首页React Native
react-native-image-picker

react-native-image-picker

作者: Kris_lee | 来源:发表于2017-05-15 23:33 被阅读4851次

对于react native 我们一定会用到相册和相机,项目中的应用也不会少。。。今天我就来介绍一个项目中,我用到的。react-native-image-picker这个控件,git地址

先来看展示效果,

图片的效果是我没有加入接口的效果。如果加入接口,我用的是base64,之后会返回一个服务器端的filrUrl。

当然java同样可以实现批量上传的效果。

首先,我们先看下环境配置

详细的见官网,更完善。

在IOS端。-》

In the XCode's "Project navigator", right click on your project's Libraries folder ➜ Add Files to <...>

Go to node_modules ➜ react-native-image-picker ➜ ios ➜ select RNImagePicker.xcodeproj

Add RNImagePicker.a to Build Phases -> Link Binary With Libraries

For iOS 10+, Add the NSPhotoLibraryUsageDescription, NSCameraUsageDescription, and NSMicrophoneUsageDescription (if allowing video) keys to your Info.plist with strings describing why your app needs these permissions. Note: You will get a SIGABRT crash if you don't complete this step

Compile and have fun

之后就是使用了。

首先必须定义全局的一些变量在项目里  我定义的是

之后调用相机的方法是:

我在方法里使用了项目的接口。返回一个服务器端的url。作为Image 的url展示出来。

react-native-image-picker的属性还有很多,方法也有多种。在这里注重的是环境的配置,以及对组件的深入研究。这里记录下来,方便以后参考。

相关文章

网友评论

    本文标题:react-native-image-picker

    本文链接:https://www.haomeiwen.com/subject/idzdzttx.html