简体   繁体   中英

Unable to upload/start image uploader in react-native

Before I start showing my code, I want to mention that I am working on iPhone simulator.

So, I was going through this blog

Added Permissions like this (in my 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>

Followed by literally copying and pasting their code

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

Now, when I click on chose photo, it takes me to the Xcode screen where this gets opened

在此处输入图片说明

Can someone help me in figuring out what could I be doing wrong? or does it work on simulator?

将函数名称从handleChosePhoto更改为handleChoosePhoto

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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