【问题标题】:React Native - Reinstall expo after expo ejectReact Native - 在博览会弹出后安装博览会
【发布时间】:2019-07-24 20:36:22
【问题描述】:

我在使用 react-native-image-picker 库时遇到问题。因此,我尝试将 RCTCameraRoll 链接到 Xcode 库中。但是,要使用 Xcode 打开我的项目,我必须运行 expo eject

现在,我该如何运行我的项目?运行命令时:expo start 它返回:

Property 'expo' in app.json is not an object. Please make sure app.json includes a managed Expo app config like this: {"expo":{"name":"My app","slug":"my-app","sdkVersion":"..."}}
No Expo configuration found. Are you sure this is a project directory?

【问题讨论】:

    标签: react-native expo


    【解决方案1】:

    如果你想使用expo,你可以使用ImagePicker,但你不必将Expo做成一个独立的应用程序。 p>

    你可以运行expo install expo-image-picker

    用法

    import * as React from 'react';
    import { Button, Image, View } from 'react-native';
    import * as ImagePicker from 'expo-image-picker';
    import Constants from 'expo-constants';
    import * as Permissions from 'expo-permissions';
    
    export default class ImagePickerExample extends React.Component {
      state = {
        image: null,
      };
    
      render() {
        let { image } = this.state;
    
        return (
          <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
            <Button
              title="Pick an image from camera roll"
              onPress={this._pickImage}
            />
            {image &&
              <Image source={{ uri: image }} style={{ width: 200, height: 200 }} />}
          </View>
        );
      }
    
      componentDidMount() {
        this.getPermissionAsync();
      }
    
      getPermissionAsync = async () => {
        if (Constants.platform.ios) {
          const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
          if (status !== 'granted') {
            alert('Sorry, we need camera roll permissions to make this work!');
          }
        }
      }
    
      _pickImage = async () => {
        let result = await ImagePicker.launchImageLibraryAsync({
          mediaTypes: ImagePicker.MediaTypeOptions.All,
          allowsEditing: true,
          aspect: [4, 3],
        });
    
        console.log(result);
    
        if (!result.cancelled) {
          this.setState({ image: result.uri });
        }
      };
    }
    

    【讨论】:

    • 我收到警告:“[未处理的承诺拒绝:错误:缺少相机胶卷权限。]”使用 iOS 模拟器
    猜你喜欢
    • 1970-01-01
    • 2020-07-22
    • 1970-01-01
    • 2022-07-15
    • 2020-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多