Deep links, magic links, or universal links are useful in your mobile application. Using it, we can provide a very smooth experience to app users. We can use these links to verify users after login or signup, reset a password, etc.
So using it, we can prevent duplicate or unwanted users from our application. So it can be very useful in our app product development. This article will explain how to implement react native deep linking in your mobile app.
1. First, at the root of your website or server, you need to add a .well-known folder.
2. In that folder, you need to upload 2 files, one for android and the other for iOS.
3. For the iOS platform, you need to upload one file named apple-app-site-association and ensure it does not contain an extension. File data can be like this given below :
{ "applinks": { "apps": [], "details": [ { "appID": "55QQP72PTY.com.mb.travelrite.dev", "paths": [ "*" ] } ] } }
We must maintain the format for appID; otherwise, dynamic links will not work. The format will be your-app-teamid.bundleId. You can choose multiple paths as per your requirement. For example, * will work for all kinds of paths.
Related Read: Deep Linking in React Native Using Firebase Dynamic Links
4. For the android platform, you need to upload a file named assetlinks.json, containing an extension. File data can be like this given below :
[ { "relation": [ "delegate_permission/common.handle_all_urls" ], "target": { "namespace": "android_app", "package_name": "com.mb.travelrite.dev", "sha256_cert_fingerprints": [ "FA:C6:17:45:DC:09:03:78:6F:B9:ED:E6:2A:96:2B:39:9F:73:48:F0:BB:6F:89:9B:83:32:66:75:91:03:3B:9C", "24:1C:DF:AE:46:70:B1:3E:48:0F:74:C9:77:10:12:B8:9F:FC:CA:4B:BD:BC:C1:44:EA:7A:63:AD:F3:EB:FE:DC" ] } } ]
For android package_name, you need to add your app’s package name. You need to add the SHA256 fingerprint of your app’s Keystore. You can get it by this command :
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
5. You must set the same package name and bundle id for both platforms; otherwise, it will not work.
6. Now we have to do configuration on the android and iOS native side so we can handle deep incoming links and perform related actions.
7. So first, we will configure the android side. In AndroidManifest.xml, we must add intent filters to the activity that handles deep linking for our app. It will catch the deep links of your domain, and clicking on the link will redirect to our app if installed. The code snippet is given below.
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher" android:allowBackup="false" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter android:autoVerify="true"> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:scheme="https" android:host="admin.dev.travelrite.org"/> <data android:scheme="http" android:host="admin.dev.travelrite.org"/> </intent-filter> </activity>
8. Now we will do it for the iOS side. Open your project in Xcode and open your app under the TARGETS header. Click the Signing & Capabilities tab. You must ensure your Team is registered and your Provisioning Profile field is completed. Please add the domain you created to the Associated Domains and prefix it with applinks: like the one below.
Related Read: How to Handle Deep Linking in a React Native Ios App?
9. Click the Info tab, and add a URL Type to your project. The Identifier can be called Bundle Id or whatever you wish. Add your bundle identifier to the URL Schemes property like the one below.
10. We have to modify the AppDelegate.m file and add some code related to linking, which handles params from deep linking and will pass to the react-native app. The code snippet is given below.
#import <React/RCTLinkingManager.h> // ... - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [RCTLinkingManager application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; }
11. Now we will do the coding part on the react-native side through which we can handle incoming deep linking and perform actions based on our requirements. First, we have to add linking listeners to our application, as given below. You can add this in a separate listener file and App.js file.
import React, { useEffect, useState } from 'react'; import { Linking, Text, View } from 'react-native'; useEffect(() => { /** * When app will in foreground and background mode */ Linking.addEventListener("url", (data) => { if (!isEmptyOrNull(data)) { handleLink(data?.url) } }) /** * When app will in killed mode */ Linking.getInitialURL().then((data) => { if (!isEmptyOrNull(data)) { handleLink(data) } }) }, [])
12. You can test the deep linking in a simulator or device by hitting a command like the one below.
iOS: npx uri-scheme open "https://admin.dev.travelrite.org" --ios android: npx uri-scheme open "https://admin.dev.travelrite.org" --android
Demo Link : Click here
So here I have shown how to implement react native deep linking in your mobile app. It will be very useful for the user perspective experience. We can implement more schemes and use them as per more requirements.
By using these steps, your app will be ready to handle deep links, and we can provide a better flow for users to use the app. Moreover, we can authorize the user and reduce unwanted methods like OTP. So apps can be more productive.
Ronak is a React-Native developer with more than 4 years of experience in developing mobile applications for Android and iOS. He is dedicated to his work and passion. He worked in different kinds of application industries that have responsive designs. He also has knowledge of how to make an app with expo cli and react-native web and some basic understanding of react.js.
How to Effectively Hire and Manage a Remote Team of Developers.
Download NowMindbowser played a crucial role in helping us bring everything together into a unified, cohesive product. Their commitment to industry-standard coding practices made an enormous difference, allowing developers to seamlessly transition in and out of the project without any confusion....
CEO, MarketsAI
I'm thrilled to be partnering with Mindbowser on our journey with TravelRite. The collaboration has been exceptional, and I’m truly grateful for the dedication and expertise the team has brought to the development process. Their commitment to our mission is...
Founder & CEO, TravelRite
The Mindbowser team's professionalism consistently impressed me. Their commitment to quality shone through in every aspect of the project. They truly went the extra mile, ensuring they understood our needs perfectly and were always willing to invest the time to...
CTO, New Day Therapeutics
I collaborated with Mindbowser for several years on a complex SaaS platform project. They took over a partially completed project and successfully transformed it into a fully functional and robust platform. Throughout the entire process, the quality of their work...
President, E.B. Carlson
Mindbowser and team are professional, talented and very responsive. They got us through a challenging situation with our IOT product successfully. They will be our go to dev team going forward.
Founder, Cascada
Amazing team to work with. Very responsive and very skilled in both front and backend engineering. Looking forward to our next project together.
Co-Founder, Emerge
The team is great to work with. Very professional, on task, and efficient.
Founder, PeriopMD
I can not express enough how pleased we are with the whole team. From the first call and meeting, they took our vision and ran with it. Communication was easy and everyone was flexible to our schedule. I’m excited to...
Founder, Seeke
Mindbowser has truly been foundational in my journey from concept to design and onto that final launch phase.
CEO, KickSnap
We had very close go live timeline and Mindbowser team got us live a month before.
CEO, BuyNow WorldWide
If you want a team of great developers, I recommend them for the next project.
Founder, Teach Reach
Mindbowser built both iOS and Android apps for Mindworks, that have stood the test of time. 5 years later they still function quite beautifully. Their team always met their objectives and I'm very happy with the end result. Thank you!
Founder, Mindworks
Mindbowser has delivered a much better quality product than our previous tech vendors. Our product is stable and passed Well Architected Framework Review from AWS.
CEO, PurpleAnt
I am happy to share that we got USD 10k in cloud credits courtesy of our friends at Mindbowser. Thank you Pravin and Ayush, this means a lot to us.
CTO, Shortlist
Mindbowser is one of the reasons that our app is successful. These guys have been a great team.
Founder & CEO, MangoMirror
Kudos for all your hard work and diligence on the Telehealth platform project. You made it possible.
CEO, ThriveHealth
Mindbowser helped us build an awesome iOS app to bring balance to people’s lives.
CEO, SMILINGMIND
They were a very responsive team! Extremely easy to communicate and work with!
Founder & CEO, TotTech
We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.
Co-Founder, TEAM8s
Mindbowser was very helpful with explaining the development process and started quickly on the project.
Executive Director of Product Development, Innovation Lab
The greatest benefit we got from Mindbowser is the expertise. Their team has developed apps in all different industries with all types of social proofs.
Co-Founder, Vesica
Mindbowser is professional, efficient and thorough.
Consultant, XPRIZE
Very committed, they create beautiful apps and are very benevolent. They have brilliant Ideas.
Founder, S.T.A.R.S of Wellness
Mindbowser was great; they listened to us a lot and helped us hone in on the actual idea of the app. They had put together fantastic wireframes for us.
Co-Founder, Flat Earth
Ayush was responsive and paired me with the best team member possible, to complete my complex vision and project. Could not be happier.
Founder, Child Life On Call
The team from Mindbowser stayed on task, asked the right questions, and completed the required tasks in a timely fashion! Strong work team!
CEO, SDOH2Health LLC
Mindbowser was easy to work with and hit the ground running, immediately feeling like part of our team.
CEO, Stealth Startup
Mindbowser was an excellent partner in developing my fitness app. They were patient, attentive, & understood my business needs. The end product exceeded my expectations. Thrilled to share it globally.
Owner, Phalanx
Mindbowser's expertise in tech, process & mobile development made them our choice for our app. The team was dedicated to the process & delivered high-quality features on time. They also gave valuable industry advice. Highly recommend them for app development...
Co-Founder, Fox&Fork