30秒到達戰場
2023-09-28 17:41:53
我目前正在開發一個小型應用程序,我想將相機膠卷中的圖像加載到應用程序中。我已經在 Expo Image Picker 文檔的幫助下構建了一個組件來執行此操作。遺憾的是,我總是在我的博覽會客戶端中收到以下警告,并且我無法從相機膠卷中選取任何圖像。當我單擊按鈕選擇它們時,它就保持原樣。我的代碼:import React, {useEffect, useState} from 'react';import { View, Image, TouchableOpacity, PermissionsAndroid, Alert, Platform, StyleSheet } from 'react-native';import * as Permissions from 'expo-permissions';import ImagePicker from 'expo-image-picker';import { MaterialIcons } from '@expo/vector-icons'export default function ImageChooser() { const [imageSource, setImageSource] = useState([]); getPermissionAsync = async () => { const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL); if (status !== 'granted') { alert('Sorry, we need camera roll permissions to make this work!'); } }; useEffect(() => { getPermissionAsync(); }, []); _getPhotoLibrary = async () => { let result = await ImagePicker.launchImageLibraryAsync({ allowsEditing: true, aspect: [4, 3] }); if (!result.cancelled) { setImageSource({ image: result.uri }); } } return ( <View style={styles.container}> <TouchableOpacity style={styles.button} onPress={() => _getPhotoLibrary()}> {!imageSource && <MaterialIcons name="add-a-photo" style={styles.icon} size={36} />} {/* {imageSource && <Image source={{uri:imageSource}} style={styles.image} />} */} </TouchableOpacity> </View> )}const styles = StyleSheet.create({ container: { paddingLeft: 20, paddingVertical: 10 }, button: { flex: 1, alignItems: 'center', justifyContent: 'center', width: 200, height: 150, borderWidth: 1, borderColor: '#C6C6C8', borderRadius: 5, backgroundColor: '#fff' }, image: { width: 200, height: 150 }, icon: { color: '#C6C6C8' }})
4 回答

楊魅力
TA貢獻1811條經驗 獲得超6個贊
您可能需要檢查您的 EAS 版本,以防出現問題。似乎本機模塊始終未定義,因此可能是構建問題
嘗試運行eas build:list
并導航到您收到錯誤的最新版本。然后檢查構建管道步驟。
expo doctor
標記了我正在使用的反應本機版本的問題。解決這個問題為我解決了錯誤

largeQ
TA貢獻2039條經驗 獲得超8個贊
Expo-image-picker
需要一個插件來訪問本機代碼。確保您已將其包含在 app.json 中。Expo-圖像選擇器文檔
另外不要忘記重建應用程序。
{
? "expo": {
? ? "plugins": [
? ? ? [
? ? ? ? "expo-image-picker",
? ? ? ? {
? ? ? ? ? "photosPermission": "The app accesses your photos to let you share them with your friends."
? ? ? ? }
? ? ? ]
? ? ]
? }
}
將“expo-image-picker”數組添加到 app.json(應用程序配置文件)中的 plgins 數組中。

慕無忌1623718
TA貢獻1744條經驗 獲得超4個贊
2天后我意識到這個問題的原因。這是相關的世博會申請。我在其他設備上嘗試了我的應用程序,但沒有遇到這個問題。刪除 expo 并重新安裝后,我的代碼運行成功。
添加回答
舉報
0/150
提交
取消