Receive Dynamic Links on iOS


To receive the Firebase Dynamic Links that you created, you must include the Dynamic Links SDK in your app and call the handleUniversalLink: and dynamicLinkFromCustomSchemeURL: methods when your app loads to get the data passed in the Dynamic Link.

Prerequisites

Firebase Dynamic Links requires iOS 8 or newer. You can target iOS 7 in your app, but all Firebase Dynamic Links SDK calls will be no-ops if the app isn't running on iOS 8 or newer.
  1. Add Firebase to your iOS project. Include the following pod in your Podfile:
    pod 'Firebase/Analytics'
    pod 'Firebase/DynamicLinks'
  2. Run pod install and open the created .xcworkspace file.
  3. In the Firebase console, open the Dynamic Links section. Accept the terms of service if you are prompted to do so.
  4. Ensure that your app's App Store ID and your App ID prefix is specified in your app's settings. To view and edit your app's settings, go to your Firebase project's Settings page and select your iOS app.
    You can confirm that your Firebase project is properly configured to use Dynamic Links in your iOS app by opening the following URL:
    https://your_dynamic_links_domain/apple-app-site-association
    If your app is connected, the apple-app-site-association file contains a reference to your app's App ID prefix and bundle ID. For example:
    {"applinks":{"apps":[],"details":[{"appID":"1234567890.com.example.ios","paths":["/*"]}]}}
    If the details field is empty, double-check that you specified your App ID prefix. Note that your App ID prefix may not be the same as your Team ID.
  1. In the Info tab of your app's Xcode project, create a new URL type to be used for Dynamic Links. Set theIdentifier field to a unique value and the URL scheme field to be your bundle identifier, which is the default URL scheme used by Dynamic Links.
  2. In the Capabilities tab of your app's Xcode project, enable Associated Domains and add the following to the Associated Domains list:
    applinks:your_dynamic_links_domain
  3. If you want to receive Dynamic Links with a fully-custom domain, in your Xcode project's Info.plist file, create a key called FirebaseDynamicLinksCustomDomains and set it to your app's Dynamic Links URL prefixes. For example:
    FirebaseDynamicLinksCustomDomains
    
      https://example.com/promos
      https://example.com/links/share
    
    
  4. Import the Firebase module in your UIApplicationDelegate:
    import Firebase
  5. Configure a FirebaseApp shared instance, typically in your app's application:didFinishLaunchingWithOptions: method:
    // Use Firebase library to configure APIs
    FirebaseApp.configure()
  6. Next, in the application:continueUserActivity:restorationHandler: method, handle links received as Universal Links when the app is already installed (on iOS 9 and newer):
    func application(_ application: UIApplication, continue userActivity: NSUserActivity,
                     restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
      let handled = DynamicLinks.dynamicLinks().handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
        // ...
      }
    
      return handled}
  7. Finally, in the application:openURL:sourceApplication:annotation: (iOS 8 and older) and application:openURL:options: (iOS 9 and up) methods, handle links received through your app's custom URL scheme. These methods are called when your app receives a link on iOS 8 and older, and when your app is opened for the first time after installation on any version of iOS.
    If the Dynamic Link isn't found on your app's first launch (on any version of iOS), this method will be called with the FIRDynamicLink's url set to nil, indicating that the SDK failed to find a matching pending Dynamic Link.
    @available(iOS 9.0, *)
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
      return application(app, open: url,
                         sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
                         annotation: "")
    }
    
    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
      if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
        // Handle the deep link. For example, show the deep-linked content or
        // apply a promotional offer to the user's account.
        // ...
        return true
      }
      return false
    }

Was this page helpful?

Comments

popular

firebase authentication using email/password

ABOUT SANTAN DHARM

HTML5 Tutorial

firebase realtime database