[英]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.