Flutterfire: [firebase_dynamic_link] v0.5.0 is not correctly working in ios in running/background state

Created on 13 Oct 2019  路  7Comments  路  Source: FirebaseExtended/flutterfire

In android application firebase dynamic link 0.5.0 is working fine. But in ios device dynamic link is not working when app is in running/background state. But in killed state it works fine means when link is clicked in killed state it open correct location in the application.
I have no idea why it is happening.
should I use one of the old versions?

bug

Most helpful comment

Here are my findings on that issue.

FirebaseDynamicLinks.instance.getInitialLink() returns null in the following situations:

  • background state / app open
  • app closed before

It only works when app is in foreground mode.

All tests with the same DynamicLink and URL clicked from Notes app on iOS Xr real device. So from what i can gather, its totally unusable at this point.

Redirecting to AppStore works without problem if the app is not installed at all.

Tested with:

import 'package:firebase_dynamic_links/firebase_dynamic_links.dart';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:logging_appenders/logging_appenders.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
    this.initDynamicLinks();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Welcome to Hello World'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Center(
              child: Text("Hello World")
            ),
          ],
        ),
      ),
    );
  }

   void initDynamicLinks() async {
    final PendingDynamicLinkData data =
        await FirebaseDynamicLinks.instance.getInitialLink();
    print("data $data");

    final Uri deepLink = data?.link;
    _logger.info("deeplink $deepLink");

    FirebaseDynamicLinks.instance.onLink(
        onSuccess: (PendingDynamicLinkData dynamicLink) async {
      final Uri deepLink = dynamicLink?.link;

      _logger.info("onLink $deepLink");
      if (deepLink != null) {
        print("onLink Path ${deepLink.path}");
      }
    }, onError: (OnLinkErrorException e) async {
      print("onLink error ${e.message}");
    });
  }
}

used firebase_dynamic_links: ^0.5.0+1

together with: Flutter (Channel dev, v1.10.14, on Mac OS X 10.15 19A583, locale de-DE)

All 7 comments

@dhanrajvermaRepo

The issue at https://github.com/flutter/flutter/issues/38744 has been closed and moved here. Future collaboration on this issue will be done here.

Here are my findings on that issue.

FirebaseDynamicLinks.instance.getInitialLink() returns null in the following situations:

  • background state / app open
  • app closed before

It only works when app is in foreground mode.

All tests with the same DynamicLink and URL clicked from Notes app on iOS Xr real device. So from what i can gather, its totally unusable at this point.

Redirecting to AppStore works without problem if the app is not installed at all.

Tested with:

import 'package:firebase_dynamic_links/firebase_dynamic_links.dart';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:logging_appenders/logging_appenders.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
    this.initDynamicLinks();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Welcome to Hello World'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Center(
              child: Text("Hello World")
            ),
          ],
        ),
      ),
    );
  }

   void initDynamicLinks() async {
    final PendingDynamicLinkData data =
        await FirebaseDynamicLinks.instance.getInitialLink();
    print("data $data");

    final Uri deepLink = data?.link;
    _logger.info("deeplink $deepLink");

    FirebaseDynamicLinks.instance.onLink(
        onSuccess: (PendingDynamicLinkData dynamicLink) async {
      final Uri deepLink = dynamicLink?.link;

      _logger.info("onLink $deepLink");
      if (deepLink != null) {
        print("onLink Path ${deepLink.path}");
      }
    }, onError: (OnLinkErrorException e) async {
      print("onLink error ${e.message}");
    });
  }
}

used firebase_dynamic_links: ^0.5.0+1

together with: Flutter (Channel dev, v1.10.14, on Mac OS X 10.15 19A583, locale de-DE)

To buttress @logemann's findings, it always works on iOS when the app is in the foreground mode. However, it works for me in background mode, but it appears to be random and inconsistent.

I got the same behaviour with 0.4.0+6, also.

Nevermind. Got it working just like it should. All having this same issue, please follow the setup guide on the flutter pub site.

Receiving dynamic links on iOS requires a couple more steps than Android. If you only want to receive dynamic links on Android, skip to step 4. You can also follow a video on the next two steps here.

In the Info tab of your iOS app's Xcode project:
Create a new URL Type to be used for Dynamic Links.
Set the Identifier field to a unique value and the URL Schemes field to be your bundle identifier, which is the default URL scheme used by Dynamic Links.
In the Capabilities tab of your app's Xcode project, enable Associated Domains and add the following to the Associated Domains list:
applinks:YOUR_SUBDOMAIN.page.link

Seems like in general this issue is resolved. For more specific cases where there are issues with the plugin please file an issue.

Was this page helpful?
0 / 5 - 0 ratings