【问题标题】:React-native iOS app crashes when taking picture拍照时 React-native iOS 应用程序崩溃
【发布时间】:2017-12-24 17:44:54
【问题描述】:

我在我的应用程序中使用react-native-camera 模块。按照说明使用here 列出的文档设置相机。设置后,我可以在 iOS 模拟器和我的 iPhone 上看到相机。但是当我单击CAPTURE 按钮时,我的应用程序在模拟器中崩溃,并且我的 iPhone 上出现以下错误:

代码如下:

import React from 'react';
import {  Text, StyleSheet } from 'react-native';
import Camera  from 'react-native-camera';

class NCamera extends React.Component {
    takePicture() {
        alert('Pressed');

        this.camera.capture()
            .then((data) => {
                console.log(data);
            })
            .catch(err => console.log(err));
    }
    render() {
        return (
            <Camera
                ref={(cam) => {
                    this.camera = cam;
                }}
                style={styles.preview}
                aspect={Camera.constants.Aspect.fill}>
                <Text style={styles.capture} onPress={this.takePicture.bind(this)}>[CAPTURE]</Text>
            </Camera>
        );
    }
}

请注意,如果我删除 capture 方法(下面的代码),应用程序不会崩溃并且在模拟器和 iPhone 中都可以正常工作。所以下面的代码肯定有一些问题,我无法弄清楚是什么。

this.camera.capture()
            .then((data) => {
                console.log(data);
            })
            .catch(err => console.log(err));

【问题讨论】:

    标签: javascript ios iphone react-native react-native-camera


    【解决方案1】:

    解决方案

    我忘记在your_project/ios/your_project/Info.plist 中添加以下内容,以允许您的应用向用户的照片库写入权限。

    <key>NSPhotoLibraryAddUsageDescription</key>
    <string>Your message to user when the photo library is accessed for the first time</string> 
    

    【讨论】:

      猜你喜欢
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      • 1970-01-01
      • 1970-01-01
      • 2017-01-30
      • 2013-10-02
      • 1970-01-01
      相关资源
      最近更新 更多