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.68k stars 3.97k forks source link

🐛 [firebase_dynamic_links ] Why dynamic link is not working on ios device when app is in running/background state? #6242

Closed kalyani6474 closed 2 years ago

kalyani6474 commented 3 years ago

Why dynamic link is not working on ios device when app is in running/background state? and i observed when app is removed from background then it is working fine according to expectation.

darshankawar commented 3 years ago

@kalyani6474

Does it work on Android ?

Can you provide flutter doctor -v and a complete minimal reproducible code sample that shows the issue ?

kalyani6474 commented 3 years ago

Yes It works on Android.

It works on IOS also. but first we need to remove app from background [everytime]. then it works in IOS.

darshankawar commented 3 years ago

@kalyani6474 If I understand the behavior correctly, when you click on the link and app is in background, the app doesn't open, but if you click the link when app is closed or in foreground, it works properly ?

In the app background scenario, does it throw any error ? like, is data comes back with null or do you see any other log ?

As requested earlier, please provide flutter doctor -v and minimal code sample that shows this issue.

kalyani6474 commented 3 years ago

when i click on the link and app is in background, the app will open, but not get deeplink and its data. when i removed app from background, then click on link, app will open and get deeplink and its data too.

In the app background scenario, No error. After closing app doesn't show any logs.

darshankawar commented 3 years ago

As requested earlier, please provide flutter doctor -v and minimal code sample that shows this issue.

darshankawar commented 3 years ago

May be similar / related to https://github.com/FirebaseExtended/flutterfire/issues/4716

google-oss-bot commented 3 years ago

Hey @kalyani6474. 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!

aguenter commented 3 years ago

Hello, i might have the same issue. I use the code below. My flutter doctor -v shows no issues. Everything runs properly on Android. With iOS, I have found the following behaviour, but only on a few devices:

In summary, I think that the callback is not registered on some iOS devices or on some iOS Versions. For now, I can not tell which devices or versions are affected. I am going to reproduce the issue in a Hello-World-App and post my results in a few days.

Code sample ``` void initDynamicLinks() async { FirebaseDynamicLinks.instance.onLink( onSuccess: (PendingDynamicLinkData dynamicLink) async { final Uri deepLink = dynamicLink?.link; if (deepLink != null) { Navigator.pushNamed(context, deepLink.path); } }, onError: (OnLinkErrorException e) async { print('onLinkError'); print(e.message); } ); final PendingDynamicLinkData data = await FirebaseDynamicLinks.instance.getInitialLink(); final Uri deepLink = data?.link; if (deepLink != null) { Navigator.pushNamed(context, deepLink.path); } } ```
jbryanh commented 3 years ago

I am experiencing similar behavior. On a physical device, in debug mode, for a firebase auth email link, i get the following errors, but it does not register an onLink. In the past it would. I'll create a full issue as best I can in a separate submission if needed. Just don't have the time to figure out how to create a reproduceable project, which is where these bugs go to thrive when you have the wrong person monitoring.

8.0.0 - [Firebase/Analytics][I-ACS023001] Deep Link does not contain valid required params. URL params: { amv = 12; apn = "com.myapp.myapp"; ibi = "com.myapp.myapp"; ifl = "https://myapp.firebaseapp.com/__/auth/action?apiKey=1234&mode=signIn&oobCode=1234&continueUrl=https://mysite.com&lang=en"; link = "https:/myapp.firebaseapp.com/__/auth/action?apiKey=1234&mode=signIn&oobCode=1234&continueUrl=https://mysite.com&lang=en"; } *****NOTE ABOVE: only one / ...this is not a typo. A "/" seems to be missing, and might be the issue.

FLTFirebaseDynamicLinks: Unknown error occurred when attempting to handle a universal link: Error Domain=com.firebase.dynamicLinks Code=500 "(null)" UserInfo={message=Internal error encountered., status=INTERNAL, code=500}

jbryanh commented 3 years ago

After migrating to version with null safety, I started to experience this behavior.

AntoninaLegkaya commented 3 years ago

Hi! I have problems with dynamic link on IOS 14.4.2 when i click on the link and app is in background, the app will open, but not get deeplink and its data. when i removed app from background, then click on link, app will open, but not get deeplink and its data too. In logs XCode i saw 2021-06-11 12:16:48.031694+0300 Runner[1518:170517] [connection] nw_read_request_report [C1] Receive failed with error "Software caused connection abort". XCode 12.4 and build version 12D4E. I try to find how fix it, but i couldn't.I need help. On Android all work correct.

google-oss-bot commented 3 years ago

Hey @kalyani6474. 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!

vemarav commented 3 years ago

adding await Future.delayed(Duration.zero) worked for me when ios app is in background.

app link - https://apps.apple.com/us/app/gist-tech-news-in-100-words/id1559849614

aguenter commented 3 years ago

@vemarav Hello, where exactly did you add this line?

vemarav commented 3 years ago

@aguenter

await Future.delayed(Duration.zero);
var data = await FirebaseDynamicLinks.instance.getInitialLink();
 var deepLink = data?.link;

and

    FirebaseDynamicLinks.instance.onLink(onSuccess: (dynamicLink) async {
     await Future.delayed(Duration.zero)
      var deepLink = dynamicLink?.link;
      final path = deepLink?.path;
      navigateOnDynamicLink(path);
    }, onError: (e) async {
      debugPrint('DynamicLinks onError $e');
    })

setup google meet at vemaravv@gmail.com if it's still not working

google-oss-bot commented 3 years ago

Hey @kalyani6474. 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!

yoondeokn commented 3 years ago

still not working on iOS, Adding await Future.delayed(Duration.zero); not working too

google-oss-bot commented 3 years ago

Hey @kalyani6474. 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!

mvrsn commented 3 years ago

I've been trying to get to the bottom of this problem and I think I may have come across something that is a problem at least in my app/setup. I'm not sure if this is exactly the same problem as this issue or if it should be a separate issue, but I'll share my findings

My setup was working to the extent that the email is being sent out with the correct custom domain, and when I click the link in the email app on the device the app opens, but the onLink listener is never triggered. I started suspecting the FirebaseDynamicLinks pod was the culprit and after a lot of breakpoints I finally found something that doesn't look right

Inside the FIRDLIsURLForAllowedCustomDomain method in FDLUtilities this check is being done urlStr.length > domainURIPrefixStr.length + 1 && ([urlStr characterAtIndex:domainURIPrefixStr.length] == '/')

At first this looked legit, until I noticed that the / that is being looked for in urlStr is not actually there, and a ? is found instead, meaning that customDomainMatchFound will be false

Looking at the link found in the email, the / is where it should be, so somewhere along the way this character seems to be intentionally removed from the link making this if-statement fail

Why and where this happens I haven't been able to find out yet, but maybe it can point someone else in the right direction for a proper solution

jbryanh commented 3 years ago

I've been trying to get to the bottom of this problem and I think I may have come across something that is a problem at least in my app/setup. I'm not sure if this is exactly the same problem as this issue or if it should be a separate issue, but I'll share my findings

My setup was working to the extent that the email is being sent out with the correct custom domain, and when I click the link in the email app on the device the app opens, but the onLink listener is never triggered. I started suspecting the FirebaseDynamicLinks pod was the culprit and after a lot of breakpoints I finally found something that doesn't look right

Inside the FIRDLIsURLForAllowedCustomDomain method in FDLUtilities this check is being done urlStr.length > domainURIPrefixStr.length + 1 && ([urlStr characterAtIndex:domainURIPrefixStr.length] == '/')

At first this looked legit, until I noticed that the / that is being looked for in urlStr is not actually there, and a ? is found instead, meaning that customDomainMatchFound will be false

Looking at the link found in the email, the / is where it should be, so somewhere along the way this character seems to be intentionally removed from the link making this if-statement fail

Why and where this happens I haven't been able to find out yet, but maybe it can point someone else in the right direction for a proper solution

Agree. The missing / is what I observed to be the issue.

mvrsn commented 3 years ago

@darshankawar could the blocked: customer response label be removed from this issue so that it could get some more attention, or would it be better if either of us opens a new issue? I feel like the findings from @jbryanh and myself could be where the problem lies

google-oss-bot commented 3 years ago

Hey @kalyani6474. 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!

mvrsn commented 3 years ago

This issue is not stale 😅

markusaksli-nc commented 3 years ago

I'll label this for now based on the number of reports and attempt to reproduce the issue but for those of you facing this could you specify how exactly you are opening the link?

markusaksli-nc commented 3 years ago

I wasn't able to reproduce the issue on the latest firebase_dynamic_links: ^2.0.7. The link opens with the appropriate data when the app is backgrounded or terminated when opening with the Open in appname context menu option on iOS.

flutter doctor -v ``` [✓] Flutter (Channel master, 2.5.0-7.0.pre.66, on macOS 11.5.1 20G80 darwin-arm, locale en-GB) • Flutter version 2.5.0-7.0.pre.66 at /Users/nevercode/development/flutter_master • Upstream repository https://github.com/flutter/flutter.git • Framework revision bf3ff7ec71 (3 hours ago), 2021-08-13 15:22:07 +0800 • Engine revision 670a681c1d • Dart version 2.15.0 (build 2.15.0-6.0.dev) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /Users/nevercode/Library/Android/sdk • Platform android-30, build-tools 30.0.3 • Java binary at: /Users/nevercode/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7583922/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.5.1, Build version 12E507 • CocoaPods version 1.10.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2020.3) • Android Studio at /Users/nevercode/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7583922/Android Studio.app/Contents • Flutter plugin can be installed from: � https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: � https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189) [✓] Android Studio (version 2020.3) • Android Studio at /Users/nevercode/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7583922/Android Studio.app/Contents • Flutter plugin can be installed from: � https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: � https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189) [✓] Connected device (3 available) • Nevercode’s iPhone (mobile) • b668e524315069f3db3661ac11ff1f66afafebdb • ios • iOS 14.7.1 18G82 • macOS (desktop) • macos • darwin-arm64 • macOS 11.5.1 20G80 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 92.0.4515.131 ! Error: Nevercode’s iPhone is busy: Copying cache files from device. Xcode will continue when Nevercode’s iPhone is finished. (code -10) • No issues found! ```
mvrsn commented 3 years ago

I just realized that nowhere above I forgot to mention that this issue I am having is specifically related to the email signing using Firebase Auth which seems to be the same issue that @jbryanh is having, but might not correspond fully to the problem of the original issue

When putting a breakpoint in the FIRDLIsURLForAllowedCustomDomain method in FDLUtilities the value of urlStr is something like this (broken up for legibility)

URL NSURL * @"https://dynamic-link.myapp.com
  ?link=https://myapp.firebaseapp.com/__/auth/action?apiKey%3D...%26mode%3DsignIn%26oobCode%...%26continueUrl%3Dhttps://dynamic-link.myapp.com/sign-in%26lang%3Den
  &apn=com.myapp
  &amv
  &afl=https://myapp.firebaseapp.com/__/auth/action?apiKey%3D...%26mode%3DsignIn%26oobCode%3D...%26continueUrl%3Dhttps://dynamic-link.myapp.com/sign-in%26lang%3Den
  &ibi=com.myapp&ifl=https://myapp.firebaseapp.com/__/auth/action?apiKey%3D...%26mode%3DsignIn%26oobCode%3D...%26continueUrl%3Dhttps://dynamic-link.myapp.com/sign-in%26lang%3Den"

This makes the check [urlStr characterAtIndex:domainURIPrefixStr.length] fail as it will not find the expected / after the .com but the ?

Looking at the link in my email the / is there, so something along the way is removing it

I still didn't manage to figure out where this URL is coming from or even how to debug this further, but if anyone can point me in the right direction I'd also be happy to investigate it myself

felipemy commented 3 years ago

I'm also facing this kind of error. Despite of following every step on plugin Docs, when using Firabase auth for signin a user with the Dynamic Link .sendSignInLinkToEmail(), on IOS it always display the error:

Deep Link does not contain valid required params. URL params: {...}

This goes after opening the link received on email. The app is opened, but reading the link data fails with this error. This only occurs in IOS, Android is working as expected.

Everything on flutter doctor is correct. Tested with plugin version 2.0.9

danielstuart14 commented 3 years ago

Same issue on IOS 12 with latest firebase plugins. It is happening while opening a dynamic link generated by firebase auth.

MyisCARRY commented 3 years ago

Same issue on iOS 14.6, firebase_dynamic_links: 2.0.9. Works fine on Android. When app is in the background, deeplink opens the app but the FirebaseDynamicLinks.instance.onLink never tiggers.

MyisCARRY commented 3 years ago

What helped me was always calling FirebaseDynamicLinks.instance.getInitialLink() at the start of the app. After calling this, my FirebaseDynamicLinks.instance.onLink works properly.

felipemy commented 3 years ago

@MyisCARRY , could you please an example of how you implemented this? I'm running FirebaseDynamicLinks.instance.getInitialLink() on main.dart before calling runApp(MyApp()); and it stills doesn't work.

MyisCARRY commented 3 years ago

@felipemy

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

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    FirebaseDynamicLinks.instance.getInitialLink();
    FirebaseDynamicLinks.instance.onLink(...);

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return ...;
  }
}
felipemy commented 3 years ago

@MyisCARRY, thanks for sharing! I tried implementing this way and it worked only when the app is first launched. If another link is sent again afterwards, the error is thrown again. Also tested by calling in WidgetsBinding.instance.addPostFrameCallback(), didChangeDependencies() and even at didChangeAppLifecycleState(if resumed), but the error persists. The only way to get the link working again is by killing the app and run all again (or hot restart). So in my case doesn't solve yet.

mvrsn commented 3 years ago

I am still not having any success with this after a couple of months when it comes to catching the login link from the email sign in, what am I doing wrong?

Would love to have some feedback on the two previous posts I made on this thread as well if possible, I still believe that is the culprit

@markusaksli-nc when you said you couldn't reproduce it, was this just with a dynamic link, or using the firebase_auth email signin link? If they are being treated as the same story maybe it would be better to open https://github.com/FirebaseExtended/flutterfire/issues/6805 again since ut is specifically related to the dynamic_links + auth combo

stact commented 2 years ago

Got same issue but resolved with adding this following key on Info.plist

<key>FirebaseDynamicLinksCustomDomains</key>
<array>
  <string>https://example.com/link</string>
  <string>https://example.com/promos</string>
</array>

Source: https://firebase.google.com/docs/dynamic-links/custom-domains

Hope it helps.

ffaridi1 commented 2 years ago

I am also facing the same issue. One extra observation which I found and thought will be helpful for others . I have an onboarding screen where I show users some introduction and then they go to Homepage. If I open my app normally (without calling getInitLink ) and go through intro screen (which also register for onLink), the dynamic link is able to trigger callback for onLink. However when I go all the way to homepage and do same, onLink never got triggerred . Also, this only works in iPhone and in Android, no matter what I do , onLink is not fired if the App is in background/foreground. Is this something to do with Crashlytics widget ?

ffaridi1 commented 2 years ago

I have finally resolved my issue and this will definitely help someone here. In my routine where I was setting up dynamic links handling , I had the call to FirebaseDynamicLinks.instance.getInitialLink() "before" the call to FirebaseDynamicLinks.instance.onLink.listen((dynamicLinkData) .... This apparently was causing the issue and when App was launching normally, the second call was blocked because getInitialLink was returning null and function was exiting (most likely due to Nullsafty error of using null check operator on Null ) , but App was not crashing somehow as this code runs asynchronously.

Once I flipped the order and call onLink first , it starts to work as expected . In my case , iPhone was working even with old order and that might be due to some OS related feature which I don't know.

Hopefully this will help someone here.

naoaki-kaito commented 2 years ago

I still can't solve this problem. I'm using ver.4.1.2, and example code.

But it does't work when app opened from dynamicLinks web page. (works fine when App is running and Android.)

rosenstrauch commented 2 years ago

many thanks to https://github.com/firebase/flutterfire/issues/6913#issuecomment-969214337 for a working workaround to this annoying problem which totally still persists.

https://github.com/firebase/flutterfire/issues/6913#issuecomment-1084441844

damianoct commented 2 years ago

this helps me to resolve the problem: https://github.com/firebase/flutterfire/issues/6913#issuecomment-1094101508

syonkr commented 2 years ago

if you using ios, Custom domain long url and with version > 2.0.9, is that was bug. https://github.com/firebase/firebase-ios-sdk/commit/c1a33a099d36438de35d381b579185e26d6391d9 https://github.com/firebase/firebase-ios-sdk/pull/9516 it will fix to next dynamic link 8.15.0 update.

russellwheatley commented 2 years ago

Hey @kalyani6474, I've just tested this on the firebase_dynamic_links example app and it works from background and terminated state. If you wish to test a working demonstration yourself, please follow the instructions here. Thanks.

guilherme-v commented 2 years ago

Same issue on iOS 14.6, firebase_dynamic_links: 2.0.9. Works fine on Android. When app is in the background, deeplink opens the app but the FirebaseDynamicLinks.instance.onLink never tiggers.

I'm having exactly the same issue here, the workaround was to use the app_links library instead