如果安装了 React Native 重定向到应用程序,否则重定向到 App Store 或 PlayStore

问题描述

我想在按下应用链接重定向为:-

  1. 如果未安装应用,则转到 Playstore 或 AppStore。
  2. 如果已安装应用,请打开我的应用(带有深层链接)。

到目前为止我所做的:-

我使用 React 导航 5 的深层链接达到了要求 2。 如:-

import constants from '../../constants';

 const config = {
screens: {
    //SignInScreen: "SignInScreen",SignupScreen: {
        path: `${constants.Screens.SignUpScreen.name}/:id`,parse: {
            id: (id) => `${id}`,},}
},};

 const linking = {
prefixes: ["http://com.app"],config,};

 export default linking;

App.js:-

<NavigationContainer linking={linking} ref={navigationRef}>
        {
            props.global.switchApp.isLoading ?
                <SplashStack />
                :
                (
                    props.global.user.accesstoken !== null ?
                        <AppStack /> :
                        <AuthStack />
                )
        }
    </NavigationContainer>

并且 AndroidManifest.xml 中的相应更改为:-

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.broWSABLE" />
    <data
      android:host="com.app"
      android:scheme="http" />
  </intent-filter>

并在项目的 url type添加 target

Appdelegate.m 文件中为:-

- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
        options:(NSDictionary<UIApplicationopenURLOptionsKey,id> *)options {

 // Add any custom logic here.
 BOOL deepLinking =  [RCTLinkingManager application:application openURL:url options:options];
return  deepLinking;
}

我如何在使用它时达到要求 1?

谢谢!!!

解决方法

要打开应用或打开应用商店或 Play 商店,如果应用未安装,请点击应用链接,尝试使用 firebase 动态链接功能。

查看文档了解更多信息。

https://rnfirebase.io/dynamic-links/usage