5

I'm having trouble opening iOS gallery app from React Native app. I have the file url and asset url. I got the asset url from CameraRoll. Now I want to open the gallery itself to see the image.

This is the code that I use

openGallery = () => {
// this code is working on android using asset url
// sample url on iOS
// file url : file:///var/mobile/Containers/Data/Application/A41FFC2E-06D4-445D-9B94-D21E885930C7/Documents/video/popcam-1527202811.mov
// asset url : assets-library://asset/asset.mov?id=D4C62335-EDB1-4A75-B94D-61C3D48CADEA&ext=mov
const { galleryUrl, source } = this.props
const url = Platform.OS === 'ios' ? source : galleryUrl
Linking.canOpenURL(url).then(canOpen => {
  if (canOpen) {
    Linking.openURL(url)
  } else {
    Alert.alert('Info', 'Under Development')
  }
})

Thanks

Addin
  • 51
  • 1
  • 5
  • You can use cameraroll .. https://facebook.github.io/react-native/docs/cameraroll.html – digit May 25 '18 at 01:29
  • I already use camera roll to get the asset url. I got this url (asset url : assets-library://asset/asset.mov?id=D4C62335-EDB1-4A75-B94D-61C3D48CADEA&ext=mov) from camera roll. Camera roll only used to get the assets url, not opening the gallery itself – Addin May 25 '18 at 03:27
  • you can use react-native-image-picker – Ankit Aman Jul 21 '18 at 02:14

2 Answers2

12
openPhotos = () =>{
switch(Platform.OS){
  case "ios":
    Linking.openURL("photos-redirect://");
  break;
  case "android":
    Linking.openURL("content://media/internal/images/media");
  break;
  default:
    console.log("Could not open gallery app");
 }
}
Adam Richardson
  • 2,518
  • 1
  • 27
  • 31
0

Im unaware of a way to open a specific asset. However, you can open the Photos app with the following scheme:

Linking.openURL('photos-redirect://')

jwanga
  • 4,166
  • 4
  • 26
  • 27