Skip to content

docs(dynamic-links): update Firebase documentation on how to receive link from terminated state #10493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2023

Conversation

russellwheatley
Copy link
Member

@russellwheatley russellwheatley commented Feb 20, 2023

Description

As reported by this user, the iOS app could receive the link from a terminated state from either the getInitialLink method call or the event listener onLink. I believe the user can call getInitialLink before it has been passed to the app and therefore I have updated the documentation to reflect this.

If you wish to test this yourself, you can:

  1. Run the app in release mode.
  2. Open the app from a terminated state using a Dynamic Link you're created in the Firebase console and configured for your app.
  3. Use the below noted, crude code snippet in your main.dart file. Open the app and note the success rate of getInitialLink. It doesn't always successfully retrieve the Dynamic Link upon app opening. It is more successful when you uncomment the Future.delayed. The onLink will always receive the opening Dynamic Link.
import 'dart:async';

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_dynamic_links/firebase_dynamic_links.dart';
import 'package:flutter/material.dart';

import 'firebase_options.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _linkMessage = 'no-state';

  @override
  void initState() {
    super.initState();
    initDL();
  }

  Future initDL() async {
    // FirebaseDynamicLinks.instance.onLink.listen(
    //   (event) {
    //     setState(() {
    //       _linkMessage = event.link.toString() + ' onLink';
    //     });
    //   },
    // );
    // await Future.delayed(const Duration(milliseconds: 3000));
    final initialLink = await FirebaseDynamicLinks.instance.getInitialLink();

    if(initialLink != null){
      setState(() {
        _linkMessage = initialLink.link.toString() + ' getInitialLink';
      });
    } else {
      setState(() {
        _linkMessage = 'nothing' + ' getInitialLink';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Testing Something'),
          ),
          body: Column(
            children: [
              ElevatedButton(
                  onPressed: () {
                    setState(() {
                      _linkMessage = 'reset';
                    });
                  },
                  child: const Text('reset link')),
              Text(_linkMessage),
            ],
          )),
    );
  }
}

Related Issues

closes #7546

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

@russellwheatley russellwheatley marked this pull request as ready for review February 20, 2023 14:40
@russellwheatley
Copy link
Member Author

Hey @kevinthecheung, do you mind taking a look and seeing what you think? Thanks.

@Lyokone Lyokone merged commit b002063 into master Feb 28, 2023
@Lyokone Lyokone deleted the @russell/dyanmic-7546 branch February 28, 2023 07:26
@firebase firebase locked and limited conversation to collaborators Mar 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 [firebase_dynamic_link] New iOS install doesn't open with dynamic link after install
3 participants