avioli / uni_links

Flutter plugin for accepting incoming links.
BSD 2-Clause "Simplified" License
563 stars 303 forks source link

iOS - getUriLinksStream and getLinksStream don't emit #63

Open avi-mastov opened 4 years ago

avi-mastov commented 4 years ago

Describe the bug getInitialUri is working on both platforms and getUriLinksStream works on Android, but I don't get any events from getUriLinksStream and getLinksStream on iOS.

To Reproduce Steps to reproduce the behavior:

  1. I'm using a custom scheme, registered on both platforms according to the guide.
  2. Install the app on a simulator (iPhone SE 2nd gen).
  3. Force close the app.
  4. Run in terminal: xcrun simctl openurl booted "custom_scheme://my_url"
  5. The app opens and I get a breakpoint and getInitialUri returns the URL.
  6. I run once more: xcrun simctl openurl booted "custom_scheme://my_url"

Expected behavior

  1. The stream subscription on getUriLinksStream and getLinksStream is supposed to be invoked.
  2. When I repeat the same on Android, using adb shell am start -W -a android.intent.action.VIEW -d custom_scheme://my_url my.package.name, everything works as expected, so I assume my integration was correct.

Smartphone (please complete the following information):

Additional context

avi-mastov commented 4 years ago

I found the cause: I had Facebook SDK integration where I needed to override the app delegate's openURL method, so it didn't pass the call to uni_links plugin's method. I had to change my code as follows:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {

  BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
    openURL:url
    sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
    annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
  ];
  if (!handled) {
    handled = [[UniLinksPlugin sharedInstance] application:application openURL:url options:options];
  }
  return handled;
}

I didn't find any instructions in uni_links documentation regarding integration code in application: openURL:options:. Please add it.

Thank you!

avioli commented 4 years ago

Will do. Thanks for the help.

anychhoice commented 4 years ago

Is it still have to change code?

@avi-mastov Can you give me more information? I have same error.. How cam i fix it?

avi-mastov commented 4 years ago

@cyc2303 If you have some other SDK that causes override of the application:openURL:options:, then you need to add a code similar to what I wrote above. Replace the FBSDKApplicationDelegate statement with whatever is written there now. Open your AppDelegate class and look for that method.

If it's not there, and you still have this problem, then you may be using another SDK that does swizzling (overriding implementation in runtime) like Firebase does for notifications (not deep links, don't worry), and you need to look in that SDK's documentation how to disable swizzling and override manually.

anychhoice commented 4 years ago

@avi-mastov Thank you for your help. Finally I fixed it!

pawlowskim commented 4 years ago

Can confirm exact what @avi-mastov said. We have snapchat login integration and the same problem.

import uni_links

    override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        var handled:Bool = SCSDKLoginClient.application(app, open: url, options: options);
        if(!handled){
            handled = UniLinksPlugin.sharedInstance().application(app, open: url, options: options);
        }
        return handled;
    }
dev1test2019 commented 3 years ago

Thank @avi-mastov @pawlowskim Update small, simple solution:

My update

Remember import: import uni_links

I think it needs more guidance in the documentation.

m-zaink commented 3 years ago

The above solution didn't work for me. Any idea why so?

LeGoffMael commented 3 years ago

Wow thank you so much guys, indeed, when using third party applications for login that overwrite AppDelegate functions, uni_links doesn't trigger any entering links on iOS. Thank you for the solution.

// in ios/Runner/AppDelegate.swift
import uni_links

// ...

override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool {
    if UniLinksPlugin.sharedInstance().application(app, open: url, options: options) {
      return true
    }

    return false
  }
xiprox commented 3 years ago

In my case it was that I was awaiting getInitialUri() before starting to listen to the stream, which, I imagine, was making me miss the initial emission. Registering a listener before checking for initial URI fixed it.

Might be a good idea to update the example code in the docs/README, as it suggests checking for initial URL first.

shabeenabarde commented 2 years ago

The above solution didn't work for me. Any idea why so?

Where you able to resolve this? I need assistance as I am facing the same issue