效果图,因为我用的是模拟器,所以拍照功能没有效果,不过可从相册选择,下面是具体的效果图

把react-native-image-picker添加到项目

  1. yarn add react-native-image-picker

plist文件设置

  1. <key>NSPhotoLibraryUsageDescription</key>
  2. <string>$(PRODUCT_NAME) would like access to your photo gallery</string>
  3. <key>NSCameraUsageDescription</key>
  4. <string>$(PRODUCT_NAME) would like to use your camera</string>
  5. <key>NSPhotoLibraryAddUsageDescription</key>
  6. <string>$(PRODUCT_NAME) would like to save photos to your photo gallery</string>
  7. <key>NSMicrophoneUsageDescription</key>
  8. <string>$(PRODUCT_NAME) would like to your microphone (for videos)</string>

xcode设置:

  1. 1.In the XCode's "Project navigator", right click on your project's Libraries folder Add Files to <...>.
  2. 2.Go to node_modules react-native-image-picker ios select RNImagePicker.xcodeproj.
  3. Add RNImagePicker.a to Build Phases -> Link Binary With Libraries.

代码集成步骤:

  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. * @flow
  5. */
  6.  
  7. import React, {Component} from 'react';
  8. import {
  9. AppRegistry,
  10. StyleSheet,
  11. Text,
  12. View, TouchableOpacity,Image
  13. } from 'react-native';
  14. import ImagePicker from 'react-native-image-picker';
  15. export default class MyApp extends Component {
  16.  
  17. constructor(props){
  18. super(props)
  19. this.state={
  20. avatarSource:null
  21. }
  22. }
  23.  
  24. render() {
  25. const photoOptions = {
  26. title: '请选择',
  27. quality: 0.8,
  28. cancelButtonTitle: '取消',
  29. takePhotoButtonTitle: '拍照',
  30. chooseFromLibraryButtonTitle: '选择相册',
  31. allowsEditing: true,
  32. noData: false,
  33. storageOptions: {
  34. skipBackup: true,
  35. path: 'images'
  36. }
  37. };
  38.  
  39. return (
  40. <View style={styles.container}>
  41. <TouchableOpacity onPress = {()=>{
  42. ImagePicker.showImagePicker(photoOptions, (response) => {
  43. console.log('Response = ', response);
  44. if (response.didCancel) {
  45. console.log('User cancelled image picker');
  46. }
  47. else if (response.error) {
  48. console.log('ImagePicker Error: ', response.error);
  49. }
  50. else if (response.customButton) {
  51. console.log('User tapped custom button: ', response.customButton);
  52. }
  53. else {
  54. let source = { uri: response.uri };
  55. // You can also display the image using data:
  56. // let source = { uri: 'data:image/jpeg;base64,' + response.data };
  57. this.setState({
  58. avatarSource: source
  59. });
  60. }
  61. });
  62. }}>
  63. <Text style={styles.welcome}>
  64. Welcome to React Native!
  65. </Text>
  66. </TouchableOpacity>
  67. <Image source={this.state.avatarSource} style={{width:100,height:100}}/>
  68. </View>
  69. );
  70. }
  71. }
  72.  
  73. const styles = StyleSheet.create({
  74. container: {
  75. flex: 1,
  76. justifyContent: 'center',
  77. alignItems: 'center',
  78. backgroundColor: '#F5FCFF',
  79. },
  80. welcome: {
  81. fontSize: 20,
  82. textAlign: 'center',
  83. margin: 10,
  84. },
  85. instructions: {
  86. textAlign: 'center',
  87. color: '#333333',
  88. marginBottom: 5,
  89. },
  90. });
  91.  
  92. AppRegistry.registerComponent('MyApp', () => MyApp);

react-native-image-picker iOS设置的更多相关文章

  1. 如何用 React Native 创建一个iOS APP?(三)

    前两部分,<如何用 React Native 创建一个iOS APP?>,<如何用 React Native 创建一个iOS APP (二)?>中,我们分别讲了用 React ...

  2. 如何用 React Native 创建一个iOS APP?(二)

    我们书接上文<如何用 React Native 创建一个iOS APP?>,继续来讲如何用 React Native 创建一个iOS APP.接下来,我们会涉及到很多控件. 1 AppRe ...

  3. 如何用 React Native 创建一个iOS APP?

    诚然,React Native 结合了 Web 应用和 Native 应用的优势,可以使用 JavaScript 来开发 iOS 和 Android 原生应用.在 JavaScript 中用 Reac ...

  4. React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton)

    React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton) 一,需求与简单介绍 在开发项目时发现RN没有给提供RadioButton和Rad ...

  5. 封装 React Native 原生组件(iOS / Android)

    封装 React Native 原生组件(iOS / Android) 在 React Native中,有很多种丰富的组件了,例如 ScrollView.FlatList.SectionList.Bu ...

  6. React Native热更新(iOS)-Pushy

    React Native的出现,使的开发iOS代码出现了更便捷的方式.由于RN是使用脚本语言编写的,实现了"解释执行"的方式,而这种执行方式的修改只需替换脚步即可,不需要重新发布程 ...

  7. React Native项目集成iOS原生模块

    今天学习一下怎么在React Native项目中集成iOS原生模块,道理和在iOS原生项目中集成React Native模块类似.他们的界面跳转靠的都是iOS原生的UINavigationContro ...

  8. React Native环境搭建(iOS、Mac)

    http://reactnative.cn/docs/0.42/getting-started.html#content 1.安装Homebrew Homebrew, Mac系统的包管理器,用于安装N ...

  9. React Native 组建之IOS和Android通用抽屉

    /** * Sample React Native App * https://github.com/facebook/react-native * @flow *npm:https://www.np ...

  10. React Native区分安卓/iOS平台

    import { Platform, } from 'react-native'; alert(JSON.stringify(Platform)): android手机弹出:{"OS&quo ...

随机推荐

  1. 如何处理MySQL每月5亿的数据

    第一阶段:1,一定要正确设计索引2,一定要避免SQL语句全表扫描,所以SQL一定要走索引(如:一切的 > < != 等等之类的写法都会导致全表扫描)3,一定要避免 limit 100000 ...

  2. PHP伪造referer突破网盘禁止外链(附115源码)

    新建一个文件file.php.后面的参数就是需要伪造referfer的目标地址吧.如:file.php/http://www.xxx.xxx/xxx.mp3 复制内容到剪贴板 代码: <?$ur ...

  3. django 1.11.1 连接MySQL

    一.定义数据库 settings.py搜索   DATABASES 参考路径:   D:\Python27\Lib\site-packages\django\bin\app\app\settings. ...

  4. sshpass 配置密码登录ssh

    tar -zxvf sshpass-1.06.tar.gzcd sshpass-1.06./configuremake && make install sshpass -p userp ...

  5. (广度搜索)A - Prime Path(11.1.1)

    A - Prime Path(11.1.1) Time Limit:1000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64 ...

  6. db2 查杀死锁进程

    db2 查杀死锁进命令 db2 get snapshot for locks on (需要snapshot的访问权限) db2 list applications db2 "force ap ...

  7. checkbox做全部选中,全部取消效果

    批量选中.取消多个checkbox的用法很简单,这个功能也很常用.这里做个总结. 在HTML中的写法: <div id="ftpFileDownTr"> <but ...

  8. hdu2609 How many【最小表示法】【Hash】

    How many Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  9. hdu3374 String Problem【最小表示法】【exKMP】

    String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  10. 非节点主机通过内网远程管理docker swarm集群

    这是今天使用 docker swarm 遇到的一个问题,终于在睡觉前解决了,在这篇随笔中记录一下. 在 docker swarm 集群的 manager 节点上用 docker cli 命令可以正常管 ...