Reputation: 3674
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:
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));
Upvotes: 1
Views: 1629
Reputation: 3674
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>
Upvotes: 1