I am trying to use Media Library to save camera photos to the gallery. It works fine on Android. On iOS, calling MediaLibrary.createAssetAsync crashes the app. I am running it through the Expo app, not as a standalone build. This can be easily reproduced through this snack iOS createAssetAsync Crash - Snack or by running create-react-native-app and replacing App.js with the following code.
import React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
import { Constants, Camera, FileSystem, Permissions, SQLite, ScreenOrientation, KeepAwake, GestureHandler, Video, MediaLibrary } from 'expo';
export default class App extends React.Component {
componentDidMount = async () => {
await Permissions.askAsync(Permissions.CAMERA);
await Permissions.askAsync(Permissions.CAMERA_ROLL);
}
takePhoto = () => {
setTimeout(() => {
console.log('timeout');
this.camera.takePictureAsync().then(async data => {
console.log('read to create assset');
const asset = await MediaLibrary.createAssetAsync(data.uri);
console.log('successfully created asset');
});
}, 3000);
}
render() {
return (
<View style={styles.container}>
<Camera ref={ref => {
this.camera = ref;
}} style={{flex:1, width: '100%'}}>
</Camera>
<Button title="Take Photo" onPress={this.takePhoto}></Button>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Does anyone see anything that I am missing? I am using Expo SDK 27.0.1.