繁体   English   中英

无法在本机中上传/启动图片上传器

[英]Unable to upload/start image uploader in react-native

在开始显示代码之前,我想提到我正在使用iPhone模拟器。

所以,我正在浏览这个博客

像这样添加了权限(在我的info.plist中)

<key>NSPhotoLibraryUsageDescription</key>
<string>For choosing a photo.</string>
<key>NSCameraUsageDescription</key>
<string>For taking a photo.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>For saving a photo.</string>

随后按字面上复制并粘贴其代码

import React, { Component } from 'react'
import { 
  View,
  Image,
  Button,
  Text
 } from 'react-native'
import ImagePicker from 'react-native-image-picker'
class UserImage extends Component {

  state = {
    photo: null
  }

  handleChosePhoto = () => {
    const options = {
      noData: true
    }

    ImagePicker.launchImageLibrary(options, response => {
      if (response.uri) {
        this.setState({ photo: response });
      }
    });
  }

  render () {
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      {this.state.photo && (
        <Image
          source={{ uri: photo.uri }}
          style={{ width: 300, height: 300 }}
        />
      )}
      <Button title="Choose Photo" onPress={this.handleChosePhoto} />
    </View>
    )
  }

}

export default UserImage

现在,当我单击选择的照片时,它将带我到Xcode屏幕,该屏幕将打开

在此处输入图片说明

有人可以帮助我弄清楚我该怎么做吗? 还是可以在模拟器上使用?

将函数名称从handleChosePhoto更改为handleChoosePhoto

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM