flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[firebase_dynamic_links] Not working on app start

Open MaciDE opened this issue 7 years ago • 45 comments

Describe the bug When opening an iOS App from a dynamic link the initialLink is nil.

To Reproduce Steps to reproduce the behavior:

  1. Set up firebase dynamic links for a project as described in the readme.
  2. Create a dynamic link (programmatically or via console)
  3. 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 avatar Sep 06 '19 12:09 MaciDE

@MaciDE Have you found a way to fix this issue or a workaround? Currently experiencing this issue myself.

DanielScholte avatar Sep 27 '19 13:09 DanielScholte

@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();
}

MaciDE avatar Sep 27 '19 14:09 MaciDE

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

jherencia avatar Oct 03 '19 02:10 jherencia

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 :)

MaciDE avatar Oct 03 '19 09:10 MaciDE

@jherencia will test the PR tomorrow.

HofmannZ avatar Oct 04 '19 22:10 HofmannZ

@jherencia Your PR solves my issues! Been tinkering with this for 3 days straight, thanks so much!

HofmannZ avatar Oct 07 '19 19:10 HofmannZ

@jherencia I can confirm your PR fix the problem on iOS when app is in "killed state"

quetool avatar Oct 09 '19 18:10 quetool

@jherencia Yep, seems like your PR fixes the issue. Thank you!

MaciDE avatar Oct 09 '19 18:10 MaciDE

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 avatar Oct 10 '19 20:10 quetool

@quetool did not try it trough the App Store yet

HofmannZ avatar Oct 10 '19 20:10 HofmannZ

@HofmannZ doesn't matter app store, you can simulate app installation by running the project without the app installed. The steps are...

  1. Uninstall app
  2. Tap on a dynamic link
  3. Wait for App Store to open
  4. With App Store opened run your project and wait.

Dynamic link should work after installation (like in Android do)

quetool avatar Oct 10 '19 20:10 quetool

It seems to be an old iOS issue https://github.com/firebase/firebase-ios-sdk/issues/1244#issuecomment-537534792

quetool avatar Oct 10 '19 21:10 quetool

@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 avatar Oct 11 '19 07:10 MaciDE

@MaciDE

Great to hear, thank you!

jherencia avatar Oct 11 '19 11:10 jherencia

@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...

quetool avatar Oct 11 '19 12:10 quetool

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 avatar Oct 11 '19 12:10 jherencia

@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....

quetool avatar Oct 11 '19 12:10 quetool

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...

quetool avatar Oct 11 '19 20:10 quetool

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...

MaciDE avatar Nov 03 '19 11:11 MaciDE

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

jherencia avatar Nov 03 '19 20:11 jherencia