How to open iOS gallery app from React Native app

流过昼夜 提交于 2020-04-11 03:37:43

问题


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


回答1:


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



回答2:


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://')



来源:https://stackoverflow.com/questions/50519892/how-to-open-ios-gallery-app-from-react-native-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!