【问题标题】:How to open iOS gallery app from React Native app如何从 React Native 应用程序打开 iOS 画廊应用程序
【发布时间】:2018-11-04 07:17:37
【问题描述】:

我无法从 React Native 应用打开 iOS 画廊应用。 我有文件 url 和资产 url。我从 CameraRoll 获得了资产 url。现在我想打开画廊本身来查看图像。

这是我使用的代码

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')
  }
})

谢谢

【问题讨论】:

  • 我已经使用相机胶卷来获取资产 url。我从相机胶卷中得到了这个网址(资产网址:asset-library://asset/asset.mov?id=D4C62335-EDB1-4A75-B94D-61C3D48CADEA&ext=mov)。相机胶卷仅用于获取资产 url,不打开画廊本身
  • 你可以使用 react-native-image-picker

标签: ios react-native deep-linking react-native-ios camera-roll


【解决方案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】:

我不知道打开特定资产的方法。但是,您可以使用以下方案打开照片应用程序:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 2017-03-08
    • 2019-05-17
    相关资源
    最近更新 更多