avioli / uni_links

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

getUriLinksStream().listen((Uri uri) invoked twice #16

Open Chepond opened 5 years ago

Chepond commented 5 years ago

Describe the bug getUriLinksStream().listen((Uri uri) { }, onError: (err) { }); } on PlatformException { // Handle exception by warning the user their action did not succeed // return? } this method is invoked twice everytime the app is being called by scheme I am using custom deep linking, not associated one..

To Reproduce Steps to reproduce the behavior:

  1. set up custom scheme
  2. calling scheme:// in webpage javascript: windows.location = "scheme://";
  3. code invoked twice

Expected behavior code invoked once should be expected

Smartphone (please complete the following information): iOS iphone XS Max simulator iOS 12

Additional context

my code snipset as below:

Future initUniLinks() async {

try {
  String initialLink = await getInitialLink();
  getUriLinksStream().listen((Uri uri) {

    Map<String, String> query = uri.queryParameters;
    Map<String, dynamic> json = jsonDecode(query['json']);

    DeepLinkDao deepLinkDao = DeepLinkDao.fromJson(json);
    handleDeepLink(deepLinkDao);
  }, onError: (err) {
    var a = 1;
    var b = a + 1;
  });
} on PlatformException {
  // Handle exception by warning the user their action did not succeed
  // return?
}

}

d-silveira commented 4 years ago

same thing on Android

djpnewton commented 3 years ago

Same here:

I ended up doing something like this with https://pub.dev/packages/synchronized:

    // Attach a listener to catch any links when app is running in the background
    _uniLinksSub = getUriLinksStream().listen((Uri uri) async {
      await _previousUniUriLock.synchronized(() async {
        if (_previousUniUri == uri) // this seems to be invoked twice so ignore the second one
          _previousUniUri = null;   // clear the uri here though so the user can manually invoke twice
        else {
          await processUri(uri);
          _previousUniUri = uri;
        }
      });
    }, onError: (err) {
      print('uri stream error: $err');
    });
tamirrab commented 3 years ago

Same here on iOS

linjonathan2001 commented 3 years ago

Same here except it'll fire 4-5 times

igorfastronicorrea commented 2 years ago

any idea how resolve this case? same error here

vinhhoangdo commented 2 years ago

I am stuck on this issue. For detail, the uriLinkStream.listen() the onData props returns twice the same URI.

uriLinkStream.listen((Uri? uri) async {
        print('Deep link : $uri'); // I got twice comment here
      });

Anyone has ideas or solutions for this issue!!

ultraon commented 1 year ago

Any updates?

KonstantenKomkov commented 9 months ago

In my case I have an endless number of updates. It seems to depend on urls length and device, becouse i have links which was listen once. In my case phone is Huawei p20 pro.

troya2 commented 3 weeks ago

I added a 1 second delay after receiving a link like so:

  class DeepLinking {
      DateTime? _lastDeepLinkTime;
      StreamSubscription<Uri>? _appLinkSubscription;
      final _appLinks = AppLinks();

      void enable() {
          _appLinkSubscription = _appLinks.uriLinkStream.listen((appLink) {

          // poor man's debounce
          if (_lastDeepLinkTime != null && DateTime.now().difference(_lastDeepLinkTime!) < const Duration(seconds: 1)) return;
          _lastDeepLinkTime = DateTime.now();

          _handleAppLink(appLink);
      }
  }