react-native-image-picker调取照相机配置环境

安装

npm install react-native-image-picker --save
react-native link react-native-image-picker

卸载

react-native unlink react-native-image-picker
npm uninstall react-native-image-picker --save

android环境配置

1,在android/settings.gradle文件中添加如下代码

在这里插入图片描述
include ‘:react-native-image-picker’
project(’:react-native-image-picker’).projectDir = new File(settingsDir, ‘…/node_modules/react-native-image-picker/android’)

2.在android/app/build.gradle文件的dependencies中添加如下代码

在这里插入图片描述
compile project(’:react-native-image-picker’)

3.在AndroidManifest.xml文件中添加权限:

路径

在这里插入图片描述
在这里插入图片描述

ios配置环境

1.Xcode打开项目的iOS,找到Info.plist文件打开,添加下图权限

在这里插入图片描述
Privacy - Camera Usage Description
$(PRODUCT_NAME) would like to use your camera(Used for uploading user avatars)

Privacy - Microphone Usage Description
$(PRODUCT_NAME) would like to your microphone (for videos)

Privacy - Photo Library Additions Usage Description
$(PRODUCT_NAME) would like to save photos to your photo gallery (Used for save user avatars)

Privacy - Photo Library Usage Description
$(PRODUCT_NAME) would like access to your photo gallery (Used for uploading user avatars)

2.在ios项目中打开Info.plist,添加如下代码

在这里插入图片描述
NSCameraUsageDescription
( P R O D U C T N A M E ) w o u l d l i k e t o u s e y o u r c a m e r a U s e d f o r u p l o a d i n g u s e r a v a t a r s < / s t r i n g > < k e y > N S M i c r o p h o n e U s a g e D e s c r i p t i o n < / k e y > < s t r i n g > (PRODUCT_NAME) would like to use your camera(Used for uploading user avatars)</string> <key>NSMicrophoneUsageDescription</key> <string> (PRODUCT_NAME) would like to your microphone (for videos)
NSPhotoLibraryAddUsageDescription
( P R O D U C T N A M E ) w o u l d l i k e t o s a v e p h o t o s t o y o u r p h o t o g a l l e r y U s e d f o r s a v e u s e r a v a t a r s < / s t r i n g > < k e y > N S P h o t o L i b r a r y U s a g e D e s c r i p t i o n < / k e y > < s t r i n g > (PRODUCT_NAME) would like to save photos to your photo gallery (Used for save user avatars)</string> <key>NSPhotoLibraryUsageDescription</key> <string> (PRODUCT_NAME) would like access to your photo gallery (Used for uploading user avatars)

猜你喜欢

转载自blog.csdn.net/The_Small_White/article/details/103711001
今日推荐