React-native iOS app crashes when taking picture

RC_02

I am using react-native-camera module in my app. Followed instructions to setup Camera using documentation listed here. After the setup, I can see camera in iOS simulator and also on my iPhone. But when I click on CAPTURE button, my app crashes in simulator and I get following error on my iPhone: iPhone error

Here is the code :

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>
        );
    }
}

Please note, if I remove capture method (code below), the app does not crash and works fine both in simulator and iPhone. So there is definitely some problem with the code below which I am not able to figure out what.

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

Solution

I forgot to add following to your_project/ios/your_project/Info.plist which allows your app to write permission to user's photo library.

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

AsyncStorage reference crashes react native app on iOS

React Native app crashes when login

React Native: Standalone, Expo built app on Android crashes when using Facebook login (works on iOS)

Button in iOS app for selecting an image or taking a picture

App suddenly crashes after taking a picture, rotate the screen and return to the activity

React-Native ios App crashes without report

React Native (iOS) app loads nicely on wifi; crashes on LTE/cell

React Native Facebook login button crashes app in iOS Simulator

React-Native ios App crashes on my phone

Crashes when using Redux-Persist with React Native on iOS device

React Native: App crashes in simulator only when debugging is on and only on Android

react native - app crashes when goes in background (no error in log)

Debugging app crashes in react native

About react native vision camera taking picture and save

React native android app crashes in assemble release build when use react-native-device-info module

Unity in Native iOS App Crashes after Build

ios application crashes when taking a screenshot due to memory spike

React Native release build crashes on launch (iOS)

Titanium App Freezes When Taking Photo on iOS

Axios with react native not returning document and crashes app

React Native: Android app crashes, onNewIntent

React Native crashes during app:processDebugManifest

React Native Expo App crashes in Production mode

Camera crashes after taking picture and hitting ok

React Native crashes on react-native run-ios

React Native IOS app crashing when using navigation

In React Native on iOS, is there a way to determine when an app is resumed? Such as an onResume event?

Silent iOS Push Notification with React Native when app is in background

[React Native][IOS] How to catch the event when the app is opened by a notification