0

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

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

Linking.canOpenUrl("mythirdpartyapp://")

and

Linking.openUrl("mythirdpartyapp://")

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

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

4

1 回答 1

0

这些确实适用于 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}`
    )
  }
}
于 2021-01-15T06:07:50.897 回答