firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.71k stars 3.97k forks source link

🐛 [Firebase Dynamic Links] getInitialLink and onLink doesn't receive any link while application is terminated (iOS) #9829

Closed thisisyusub closed 1 year ago

thisisyusub commented 2 years ago

Bug report

Hi. I am trying to implement dynamic links using Firebase. But it does not work (it opens the application but does not catch the initial link or onLink listener). I have checked before reported solutions (in this repository) but it is not working for my case. I keep in mind that it is working on the Android side correctly.

Flutter version: 3.3.4 Xcode: 14.0.1 Tested iOS version: iOS 16+ Flutter Dynamic Links Version: 5.0.3 Firebase Core Version: 2.1.1

I want to mention some points:

I have added Associated Domains in Xcode

Screen Shot 2022-10-31 at 19 29 25

Configured Url Types

Screen Shot 2022-10-31 at 19 30 10

Turned on Associated Domains in developer.apple.com

Screen Shot 2022-10-31 at 19 31 24

Provided Apple Store ID (but it is not correct apps id it is other app, is used just for test) and Team ID

Screen Shot 2022-10-31 at 19 35 01

Steps to reproduce

Steps to reproduce the behavior:

  1. Dynamic link receiver code in main.dart
    
    final initialLinkNotifier = ValueNotifier<String?>(null);

void main() async { runZonedGuarded<Future>( () async { WidgetsFlutterBinding.ensureInitialized(); /// other logics

  FirebaseDynamicLinks.instance.onLink.listen(
  (PendingDynamicLinkData? dynamicLink) async {
    final deepLink = dynamicLink?.link;
    if (deepLink != null) {
      initialLinkNotifier.value = 'listener: ${deepLink.toString()}';
    }
  },
);

final initalLink = await FirebaseDynamicLinks.instance.getInitialLink();
if (initalLink != null) {
  initialLinkNotifier.value = 'initial: ${initalLink.link.toString()}';
}
},
(error, stack) => FirebaseCrashlytics.instance.recordError(
  error,
  stack,
  fatal: true,
),

); }

**Note**: Notifier just used to show dynamic link in the ui (working or not)

2. '...'
4. See error or incorrect behavior

### Expected behavior
I can't test it in Simulator because it gives the following error:
![Simulator Screen Shot - iPhone 14 Plus - 2022-10-31 at 19 47 03](https://user-images.githubusercontent.com/44983544/199050017-913fa2a5-4c02-4627-b683-6cfea3dd94f2.png)

But in real device (iOS 16, IPhone 11) it is working while application is running in foreground, but when app is terminated, it opens application but not catching dynamic link neither getInitialLink nor onLink listener.
--

### Flutter doctor

Run `flutter doctor` and paste the output below:

<details><summary>Click To Expand</summary>

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.3.4, on macOS 12.6 21G115 darwin-arm, locale en-AZ) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 14.0.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.3) [✓] Android Studio (version 2021.3) [✓] Android Studio (version 2021.3) [✓] VS Code (version 1.72.2) [✓] Connected device (3 available) [✓] HTTP Host Availability

• No issues found!


</details>

---

### Flutter dependencies

Run `flutter pub deps -- --style=compact` and paste the output below:

<details><summary>Click To Expand</summary>

Dart SDK 2.18.2 Flutter SDK 3.3.4 azerconnect_inside 1.0.0+9

dependencies:

dev dependencies:

dependency overrides:

transitive dependencies:


iamnijat commented 2 years ago
Future<void> handleDynamicLinks() async {
    /// launches on initial run
    final data = await FirebaseDynamicLinks.instance.getInitialLink();
    await _handleDeepLink(data);

    // listens for app-alive links taps
    FirebaseDynamicLinks.instance.onLink(onSuccess: (_data) async {
      _handleDeepLink(_data);
    });
  }

  Future<void> _handleDeepLink(
      PendingDynamicLinkData? data) async {
    final deepLink = data?.link;
    print(deepLink);
      }

I am not sure but maybe this can fix your issue

thisisyusub commented 2 years ago

@iamnijat it is not helped.

darshankawar commented 2 years ago

Thanks for the detailed report @thisisyusub Can you take a look at this issue and underlying comments and see if they help in your case ?

thisisyusub commented 2 years ago

Thanks for the detailed report @thisisyusub Can you take a look at this issue and underlying comments and see if they help in your case ?

Yeap sure, I will check out and give info.

thisisyusub commented 2 years ago

I have checked the solutions, @darshankawar.

Firstly, I have added the following lines to Info.plist:

Screen Shot 2022-11-01 at 13 42 40

According to another comment, I have checked my API key in Google Cloud Console (before it was unrestricted):

Screen Shot 2022-11-01 at 13 45 22 Screen Shot 2022-11-01 at 13 45 49

I have checked the app again with a new link created in Firebase Dynamic Link Dashboard with real ios device again and it is not working.

thisisyusub commented 2 years ago

I will check this solution for now too.

thisisyusub commented 2 years ago

@darshankawar btw, I have tested app links and it is working, it catches the initial link so the problem is coming from the Firebase side. I have checked all things again.

darshankawar commented 2 years ago

Thanks for providing these updates. Have you already configured Firebase using flutterfire configure CLI tool ? If so, can you update FlutterFire CLI by running dart pub global activate flutterfire_cli which adds the GoogleService-Info.plist to your Runner.

Also, per your findings, please run in release mode on physical device to confirm the behavior.

Also take a look at this similar issue as well.

thisisyusub commented 2 years ago

@darshankawar, I have configured it with flutterfire cli version 0.2.6. It added GoogleSerice-Info.plist to my ios/Runner folder. I have built release ipa and downloaded it to TestFlight and tested with real device. If we are using app links package it is working.

thisisyusub commented 2 years ago

@darshankawar I have checked your mentioned solutions.

darshankawar commented 2 years ago

Thanks for your patience. I am keeping this issue open and labeling for further insights on expected behavior.

/cc @russellwheatley

russellwheatley commented 2 years ago

Hey @thisisyusub, I've just tested the FlutterFire dynamic links example app, and I was able to receive the dynamic link with deeplink that opened the app from a terminated state. To test in debug mode, you just need to run the app in release mode flutter run --release and run on a device otherwise it will not work.

Results of flutter doctor

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.3.7, on macOS 12.5 21G72 darwin-x64, locale en-GB) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 14.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.2) [✓] IntelliJ IDEA Community Edition (version 2020.1.1) [✓] VS Code (version 1.73.0) [✓] Connected device (3 available) [✓] HTTP Host Availability

• No issues found!

I would encourage you to diagnose your specific problem as it seems to me you have something misconfigured.

migalv commented 1 year ago

Hello. I have the exact same issue as @thisisyusub.

My app is correctly capturing the links on Android for both cases, the app is in background or terminated. But for iOS when the app comes from the terminated state it does not capture the link.

I'm using both the getInitialLink() method and the onLink stream, to capture the Dynamic Links.

@darshankawar btw, I have tested app links and it is working, it catches the initial link so the problem is coming from the Firebase side. I have checked all things again.

Similarly to @thisisyusub the Universal Links work without issues on iOS. And I have also tried the same solutions as @thisisyusub comments in this thread with no success.

I have created a very simple project from scratch to test but with no success either.

As @russellwheatley suggests, I have tested this on real devices, ranging from iPhone XR to iPhone 12 without success.

Important The example app for this plugin only receives links on Android. Xcode has signing requirements that must be configured with an iOS app developer team id. Check the firebase_dynamic_links/README.md for more details.

I have to say that the Firebase Dynamic Links example is not fully set up for iOS as it is mentioned in its README. So I don't know how @russellwheatley has tested this example on iOS devices. But in any case if I try to clone the flutterfire repo and use the example I get an error saying that I don't have the provisioning profile for the io.flutter.plugins.firebase.dynamiclinksexample app id.

The debug view for my dynamic links shows that there are no errors/warnings, and I'm pretty sure everything is configured, I have already triple-checked.

Screenshot 2022-11-12 at 17 30 59

The only workaround that has worked for me is what @AnasBawazir proposes in this comment. But this shows that something must be wrong in the Firebase Dynamic Links SDK for Flutter

Also, something to note. Make sure you are installing the GoogleServices-Info.Plist manually, as this comment indicates, to make sure you have the correct GoogleServices-Info.plist. Currently, when using the flutterfire-cli, if your project contains a GoogleServices-Info.plist file it will not be overwritten, you have to manually delete it for it to be updated.

thisisyusub commented 1 year ago

Hello again. @russellwheatley I have checked your link. When I am debugging , It shows like this, but I have configured my app with ID az.azerconnect.inside. What is the problem here? Why is dynamic link created with com.test.app id?

Screen Shot 2022-11-17 at 09 41 54
migalv commented 1 year ago

@thisisyusub this happens to me. I believe this happens if you register an app to your Firebase project and then delete it after.

In my case, I accidentally added the QA version of my app to my Production Firebase Project and since then, the dynamic links debugger always shows the warning that my QA version is missing. Even if I add it and delete it again from the registered apps

thisisyusub commented 1 year ago

@thisisyusub this happens to me. I believe this happens if you register an app to your Firebase project and then delete it after.

In my case, I accidentally added the QA version of my app to my Production Firebase Project and since then, the dynamic links debugger always shows the warning that my QA version is missing. Even if I add it and delete it again from the registered apps

@migalv, I have not done something like this. I have configured the app this one time.

KKimj commented 1 year ago

Hello. @russellwheatley @darshankawar Thank you so much for maintaining this good Flutterfire SDK.

I am also experiencing an issue where getInitialLink does not work in iOS Terminated state.

I've been troubleshooting man-day for more than 10 days.

I share the conclusion that I have obtained so far.

What I checked is as below.

I've tried my best to verify, but the only difference I can find in the end is swift and objc.

What I want to request is below.

PS. I haven't tried to solve it yet by introducing app_links or uni_links packages. The only solution left is to introduce this packages.

Thanks! Happy New Year!

russellwheatley commented 1 year ago

Interesting findings @KKimj, I wonder if it is because users have configured a Swift iOS app 🤔.

@migalv or @thisisyusub, can either of you create a repo with a reproduction of this issue? I'm happy to configure it using FF credentials so I can test on my local machine.

Out of curiosity; do either of you have a Swift iOS app setup?

google-oss-bot commented 1 year ago

Hey @thisisyusub. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 1 year ago

Since there haven't been any recent updates here, I am going to close this issue.

@thisisyusub if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.