flutterfirebasefirebase-dynamic-links

Firebase Dynamic Link Issue with iOS app terminated state


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


Solution

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