What is Deep Linking?
Deep linking is a way to pass data to your application from any platform like, website or any other application. By tapping once on link, you can pass necessary data to your application.
By using these data application will perform operation.
It might be possible that, sometime when user does not have application on their device then you have to manage this type of situation. You have to open apple store or google play so user have option to download application.
This is the main reason we are using firebase dynamic links, you can manage these link functionality as you want. By clicking once to the link, you can navigate to iOS application or android application.
Get started
Step-2 [Create a podfile and add SDK]
Open terminal and navigate to your project directory and run following command:
pod init
Open podfile and include following pod to it
pod 'Firebase/DynamicLinks'
Run pod install and open .xcworkspace file.
Step-3 [Setting up firebase project]
Login with your Google account and go to Firebase Console.
Click on Create Project. Enter your project name and country.
Your Firebase project has been created and you have been redirected to the dashboard. You can integrate a lot of things from this one firebase project into your app.
Select platform as iOS or whatever you want to configure from dashboard.
Enter your app bundle ID and click on Add app button.
Now Go to your firebase project setting and setup App store ID and Team ID
Team ID can be found in membership portal in developer account.
You can copy any app store ID from itunes for testing purpose. Whenever user clicks on dynamic link and if your app not install in his device, User automatically redirect to app store and after installing your app redirect to specific content in your app.
Download ‘GoogleService-Info.plist’ file and add to your project.
Step-4 [Open dynamic links in your iOS app]
Select your project target and go to Info tab and add new URL Types by clicking on + sign.
Enter identifier as Bundle ID and in URL Schemes enter your bundle identifier.
Now select Capabilities tab and Enable Associated Domains and add new domain enter following line:
applinks:your_app_code.app.goo.gl
You can find out your_app_code by clicking on Dynamic links from your firebase project menu.
Run your project.
Copy the Dynamic link URL and paste into notes or any other app.
By clicking on that URL automatically redirect to your app.
Step-5 [Create a real dynamic link]
Open Dynamic Links Tab from your firebase console and tap on New Dynamic Link.
Enter your deep Link URL and Link Name and click on NEXT.
Here you can specify the behaviour when user tap on dynamic link.
You can specify the behaviour for iOS and also for android if your app is on android.
Click on Create Dynamic Link and you can see your created dynamic link in list
Copy and paste into notes and tap on it. By clicking on that link if your app installed then open it otherwise it will automatically redirect to your app page in app store. After downloading app open appropriate content into your app.
Step-6 [Handle dynamic link into your iOS app]
Open AppDelegate.swift file and write import Firebase at top.
In the didFinishLaunchingWithOptions: method, configure a FIRApp shared instance:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. FIRApp.configure() return true }
Write following method into your AppDelegate.swift file.
Here we check userActivity object and retrieve webpageURL from it.
The webpageURL is the URL pass when we create dynamic link.
Now Using handleUniversalLink() we extract dynamic link parameter and perform action as per your parameter.
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool { if let incomingURL = userActivity.webpageURL { let handleLink = FIRDynamicLinks.dynamicLinks()?.handleUniversalLink(incomingURL, completion: { (dynamicLink, error) in if let dynamicLink = dynamicLink, let _ = dynamicLink.url { print("Your Dynamic Link parameter: \(dynamicLink)") } else { // Check for errors } }) return handleLink! } return false } func handleDynamicLink(_ dynamicLink: FIRDynamicLink) { print("Your Dynamic Link parameter: \(dynamicLink)") }