【问题标题】:Checking whether you can open an external app & opening it with React Native检查您是否可以打开外部应用程序并使用 React Native 打开它
【发布时间】:2021-01-14 12:46:02
【问题描述】:

我有一个第三方应用程序,它显然有一些深度链接协议 (x-mythirdpartyapp://)。我不需要对其内容进行任何深度链接,只需打开它即可。它也不会对相应的网址做出反应(即https://mythirdpartyapp.com),因此与whatsapp相关的类似问题的答案在这里没有用处。

根据我目前的研究,这些自定义深度链接协议仅适用于 iOS,因此应该适用于 iOS

Linking.canOpenUrl("mythirdpartyapp://")

and

Linking.openUrl("mythirdpartyapp://")

但无法确认,因为我没有任何 iOS 设备。

对于 Android,您显然可以使用 Linking.sendIntent 打开意图,但这还不够,因为在我的用例中,我需要在实际发送意图之前知道是否可以发送意图。

【问题讨论】:

    标签: android ios react-native deep-linking


    【解决方案1】:

    这些确实适用于 iOS,而这对 Android 也有效:https://github.com/lucasferreira/react-native-send-intent

    这是完整的解决方案:

    
    async function canOpenApp() {
      if (Platform.OS === "android") {
        return SendIntentAndroid.isAppInstalled(ANDROID_ID)
      } else {
        return Linking.canOpenURL(URL_PROTOCOL)
      }
    }
    async function openApp() {
      if (Platform.OS === "android") {
        return SendIntentAndroid.openApp(ANDROID_ID, {})
      } else {
        return Linking.openURL(URL_PROTOCOL)
      }
    }
    async function openStore() {
      if (Platform.OS === "android") {
        return Linking.openURL(
          `https://play.google.com/store/apps/details?id=${ANDROID_ID}`
        )
      } else {
        return Linking.openURL(
          `https://apps.apple.com/${APP_STORE_LOCALE}/app/${APP_STORE_NAME}/id${APP_STORE_ID}`
        )
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-04
      • 1970-01-01
      • 1970-01-01
      • 2019-07-19
      • 1970-01-01
      • 2020-05-14
      相关资源
      最近更新 更多