[firebase_dynamic_links] Not working on app start
Describe the bug When opening an iOS App from a dynamic link the initialLink is nil.
To Reproduce Steps to reproduce the behavior:
- Set up firebase dynamic links for a project as described in the readme.
- Create a dynamic link (programmatically or via console)
- Tap on link in non-browser app
Expected behavior App should open and getInitialLink() should return the correct dynamic link.
Additional context
From my understanding there is an issue when reacting to the incoming UserActivity. onInitialLink is correctly called but returns way earlier than self.initialLink is set in the completion block from [[FIRDynamicLinks dynamicLinks]handleUniversalLink: completion: ] . Therefore on handling the method call FirebaseDynamicLinks#getInitialLink [self getInitialLink] returns nil and because of self.flutterError also being nil the result returns just with nil.
@MaciDE Have you found a way to fix this issue or a workaround? Currently experiencing this issue myself.
@MaciDE Have you found a way to fix this issue or a workaround? Currently experiencing this issue myself.
Currently, I am calling getInitialLink using a delayed future. It is not working 100%, but at least it is a workaround for now.
PendingDynamicLinkData data;
if (Platform.isIOS) {
await Future.delayed(Duration(seconds: 2), () async {
data = await FirebaseDynamicLinks.instance.getInitialLink();
});
} else {
data = await FirebaseDynamicLinks.instance.getInitialLink();
}
I've pushed a PR with the fix, can you try? You just need to point to the PR version.
firebase_dynamic_links:
git:
url: https://github.com/mrmilu/flutterfire.git
path: packages/firebase_dynamic_links
ref: firebase_dynamic_links-0.5.0+4
I've pushed a PR with the fix, can you try? You just need to point to the PR version?
firebase_dynamic_links: git: url: https://github.com/mrmilu/flutterfire.git path: packages/firebase_dynamic_links ref: firebase_dynamic_links-0.5.0+4
I'll try it next week. So far it looks pretty promising :)
@jherencia will test the PR tomorrow.
@jherencia Your PR solves my issues! Been tinkering with this for 3 days straight, thanks so much!
@jherencia I can confirm your PR fix the problem on iOS when app is in "killed state"
@jherencia Yep, seems like your PR fixes the issue. Thank you!
I just realize it is not working when app is installed for the first time by touching a dynamic link... getInitialLink() is returning always null. Did anyone solve this?
@quetool did not try it trough the App Store yet
@HofmannZ doesn't matter app store, you can simulate app installation by running the project without the app installed. The steps are...
- Uninstall app
- Tap on a dynamic link
- Wait for App Store to open
- With App Store opened run your project and wait.
Dynamic link should work after installation (like in Android do)
It seems to be an old iOS issue https://github.com/firebase/firebase-ios-sdk/issues/1244#issuecomment-537534792
@jherencia After extensively testing your PR, I can confirm that your fix is working as expected.
The dynamic link is now working when the (closed) App is opened through a dynamic link without delaying the call of FirebaseDynamicLinks.instance.getInitialLink();.
For me it is also working when the app is installed through a dynamic link. The problem mentioned by @quetool should be a problem with the use of a custom domain as he already found out.
@MaciDE
Great to hear, thank you!
@MaciDE yep, the issue I have is when using custom domains... Using default domains like page.link is quite ugly for marketing campaigns... I will try to find a solution...
I think that in that case (with custom domains) the problem is not related with this library, it's probably related to something wrong in the configuration.
@jherencia that's right, I checked with original version of the plugin and with your PR, none of them worked out in this case... Seems to be an old firebase issue, maybe some methods are missings in the iOS side of the plugin, don't really know....
So, I finally find a solution. Pretty dumb indeed... The problem was somehow AppDelegate.m in my project was created (automatically or not, don't really know) with [UIApplicationDelegate application:openURL:options:] function already in it but empty inside...
For some reason this function was "overriding" the one in the plugin so that one in the plugin was never calling...
I addition, I needed to add in [UIApplicationDelegate application:didFinishLaunchingWithOptions:] this calls...
[FIROptions defaultOptions].deepLinkURLScheme = @"my-custom-scheme";
[FIRApp configure];
The first one in order to work with customs schemes, and the second one because for some reason [FIRApp configure] is not being called inside the plugin (don't know if it is a bug or no)...
This is AppDelegate.m now
#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
@import Firebase;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[FIROptions defaultOptions].deepLinkURLScheme = @"my-custom-scheme";
[FIRApp configure];
[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
//- (BOOL)application:(UIApplication *)application
// openURL:(NSURL *)url
// options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
// // Add any custom logic here.
//
// return true;
//}
@end
So now I have Dynamic Links fully functional both on iOS and Android thanks to @jherencia with his PR and some research on my own :P
I hope it helps someone in the future...
So what is going on with this issue? Looks like the pr by @jherencia is also in an unsettled state. Does not really look that great for the open source part of flutter...
I've updated the PR, fireabase_dynamic_links 0.5.0+4 was officially published so the new valid version from my repo is:
firebase_dynamic_links:
git:
url: https://github.com/mrmilu/flutterfire.git
path: packages/firebase_dynamic_links
ref: firebase_dynamic_links-0.5.0+5