skip to Main Content

We are encountering an issue with Firebase Dynamic Links on iOS. We have a Dynamic Link (DL) that resolves to open our iOS App and pass data into the App that we can then parse and trigger functionality within the App (i.e. show a screen with the data).

There are four scenarios:

  1. iOS App is running in the background:
    1. DL is copy/pasted in the browser address bar then run → Expected behaviour
    2. DL is shared to and clicked in another App (e.g. Slack / WhatsApp) → Expected behaviour
  2. iOS App is terminated and not running in the background
    1. DL is copy/pasted in the browser address bar then run → Expected behaviour
    2. DL is shared to and clicked in another App (e.g. Slack / WhatsApp) → Unexpected behaviour. The App opens, however, the data is not passed into the App and the expected functionality does not trigger.

Therefore scenario 2.2. is where the issue resides, implying this is an issue with handling the DL from the terminated state.

So far we have explored the following:

void initDeeplinks() async {
    // Get initial dynamic link if app is started using the link
    if (Platform.isIOS) {
      // handle initial link with uni_links package because firebase_dynamic_links doesn't work correctly on iOS
      try {
        final initialLink = await getInitialLink();
        log('initial link: $initialLink');
        if (initialLink != null) onDeeplink(initialLink);
      } on PlatformException {
        log('Platform Exception');
      }
    } else if (Platform.isAndroid) {
      final dlData = await FirebaseDynamicLinks.instance.getInitialLink();
      if (dlData != null) _handleDeepLink(dlData);
    }
    // Listen for dynamic links while app is open
    FirebaseDynamicLinks.instance.onLink.listen(_handleDeepLink).onError((error) {
      log('$error');
    });
  }

Is this the expected behaviour for iOS apps in a terminated state? Shouldn’t we be able to utilize the full functionality of fully resolved Dynamic Links once the App has opened and is in the foreground?

Any comment or related experience of managing this scenario would be greatly appreciated.

Note: Using Flutter. Tested on iOS v16 & v17

2

Answers


  1. We had some trouble using the official Firebase Dynamic Links package, so we found another way.

    On iOS, we used a different package called uni_links to get the dynamic link when the app starts. We used a shorter version of the Firebase Dynamic link, so the link we get can be in two different forms:

    1. Full link (if opened in a web browser)
    2. Short link (if opened from another app)

    If we get a short link, we use a method from the Firebase Dynamic Links package, FirebaseDynamicLinks.instance.getDynamicLink(), to get the full link and its data before moving on.

    Hope this helps!

    Login or Signup to reply.
  2. Handling Firebase Dynamic Links on iOS from a terminated state can be a bit complex due to the way iOS handles deep linking and app state management. Here’s some information and recommendations that may help you address the issue:

    1- iOS App Termination Behavior: When an iOS app is terminated (not running in the background), handling deep links can be different compared to when it’s in the background or foreground. iOS tends to handle deep links differently based on the state of the app.

    2- Firebase Dynamic Links (FDL) Behavior: FDLs can behave differently depending on the scenario:

    Running in the Background: Firebase Dynamic Links typically work as expected when the app is running in the background. The FDL should open the app and provide the deep link data to your app.

    Terminated State: When the app is terminated, handling deep links can be trickier. iOS may not provide the deep link data directly to your app, and you may need to rely on other methods to retrieve it.

    3- uni_links Package: You mentioned that you are using the uni_links package to retrieve the initial link when the app is in the terminated state. It’s expected behavior that you might only get the short link when using this package because Firebase Dynamic Links might not be fully resolved in the background.

    4- Handling Terminated State: To handle deep links effectively from a terminated state, consider the following:

    a- Use a combination of uni_links and Firebase Dynamic Links.

    b- When the app is in the terminated state and the FDL is clicked, you might only get the short link. However, you can use this short link to initiate the process of resolving the FDL and fetching the deep link data. Firebase Dynamic Links should help you resolve the short link and provide the deep link data when the app is brought to the foreground.

    c- You may also consider implementing a server-based solution where you store the deep link data on your server and fetch it when the app is opened using the short link. This way, you can ensure that the data is available even if the app is terminated.

    5- Testing on Different iOS Versions: You mentioned that you tested on iOS 16 and 17, but as of my knowledge cutoff date in September 2021, iOS 17 had not been officially released. Keep in mind that iOS updates can sometimes introduce changes in behavior, so ensure that you are testing on the latest iOS version available at the time.

    6- Check for Firebase Updates: Firebase libraries, including Firebase Dynamic Links, are actively maintained, and updates can include bug fixes and improvements. Make sure you are using the latest version of the Firebase Dynamic Links SDK for Flutter.

    7- iOS Entitlements: Ensure that your app’s entitlements and associated configurations in Xcode are set up correctly. Sometimes, issues with deep linking can be related to misconfigured entitlements.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search