MediaLibrary.createAssetAsync crashes Expo on iOS

#1

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 https://snack.expo.io/HyzVZ7kCf 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.

1 Like
#2

I have the same issue. No error, the app just crashes and closes

#3

Thanks for the snack and report, this looks like a bug and we will get on it immediately.

1 Like
#4

We’ve merged a fix for this which will ship in our next minor release.

1 Like
#5

Awesome. Thank you (and bacon) for the quick response.

1 Like
closed #6

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.