Shahanshah Alam
Shahanshah Alam

Reputation: 605

React Native Redirect to application if installed, otherwise to App Store or PlayStore

I want to redirect on press of app link as:-

  1. To playstore or AppStore if app is not installed.
  2. Open my app (with deep linking) if app is installed.

What I have done till now:-

I have achieved requirement 2 using deep linking of react navigation 5. As:-

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>

And with respective changes in AndroidManifest.xml as:-

<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>

and adding url type in target of project.

And In Appdelegate.m file as:-

- (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;
}

How can I achieve requirement 1 while using this?

Thanks!!!

Upvotes: 1

Views: 8676

Answers (1)

Jignesh Mayani
Jignesh Mayani

Reputation: 7193

To open an app or open an app store or play store, on an app link click if the app not installed, try the firebase dynamic linking feature.

Check out the docs for more info.

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

Upvotes: 4

Related Questions