【问题标题】:How can i check app installed in react native code我如何检查安装在反应本机代码中的应用程序
【发布时间】:2017-10-15 18:12:22
【问题描述】:

我尝试在我的 react native 项目中检查其他应用程序安装,我使用的模块如下:https://www.npmjs.com/package/react-native-check-app-install 但总是得到这个错误: 无法读取未定义的属性“pkgName” 这是我的代码:

    AppInstalledChecker
    .isAppInstalledAndroid('com.skype.raider') 
    .then((isInstalled) => {
        // isInstalled is true if the app is installed or false if not 
         console.log('App Skype status: ', isInstalled);
    });

任何人都可以建议我一种方法,以便在 react native 中检查应用安装(两者:iOS/android)

【问题讨论】:

  • 不应该是.isAppInstalledAndroid('skype')吗?因为 pkgName 已经在 app-list 对象中定义了。来源:github.com/redpandatronicsuk/react-native-check-app-install/…
  • 我尝试了 react-native-check-app-install 并失败了,因为它真的有问题 :) 起初我决定修复一些错误,但最后我只安装了 react-native-shared-group-偏好并忘记 react-native-check-app-install :)

标签: react-native react-native-android react-native-ios


【解决方案1】:
  1. Google Play 将已安装应用列表视为个人敏感用户数据。

我们正在使用

AppInstalledChecker
    .isAppInstalledAndroid()

检查应用安装检查的方法,为此我们必须将 manifest.xml 中的查询列入白名单

参考:https://developer.android.com/training/package-visibility

<queries>
    <package android:name="com.instagram.android"/>
    …
</queries>
  1. 添加查询需要升级build gradle版本: 需要添加的 Android 11 中包可见性的新默认设置和功能,您必须更新您的 android gradle 插件版本

参考:How to fix "unexpected element <queries> found in <manifest>" error?

我已经从 3.5.2 更新到 4.0.2

现在react-native-check-app-install 模块按预期工作

希望这个问题得到解决!

【讨论】:

    【解决方案2】:

    安卓

    我。对于具有“waze://”、“mapsme://”等深层链接的应用,您可以使用:

    import { Linking } from 'react-native'
    ...
    Linking.canOpenURL('waze://ul?ll=${latitude},${longitude}&navigate=yes')
    

    二。您绝对可以用于所有应用程序(例如,使用像“https://...”这样的深层链接) https://github.com/KjellConnelly/react-native-shared-group-preferences

    iOS

    import { Linking } from 'react-native'
    ...
    Linking.canOpenURL(iOS_app_URL_Scheme)
    ...
    

    iOS_app_URL_Scheme你可以通过谷歌找到每个单独的应用程序。像“waze://”、“comgooglemaps://”、“osmandmaps://”等

    【讨论】:

      【解决方案3】:

      安装这个

      https://github.com/KjellConnelly/react-native-shared-group-preferences
      

      async check() {
          try {
              await SharedGroupPreferences.isAppInstalledAndroid("com.farsitel.bazaar")
              // IF IS INSTALL
          } catch (e) {
              // IF IS NOT INSTALL
          }
      }
      

      【讨论】:

      • ios 呢?
      • @MuhammadAshfaq 对于 iOS,您可以使用“import { Linking } from 'react-native'”,然后使用 Linking.canOpenURL(iOS_URL_scheme),其中 iOS_URL_scheme 您可以在 google 中找到每个单独的应用程序
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多