uni_links icon indicating copy to clipboard operation
uni_links copied to clipboard

getInitialUri returns NULL iOS custom URL scheme

Open andrefcferreira opened this issue 5 years ago • 7 comments

Hello guys! I have a set of custom URL schemes that are triggered with push notifications. Everything works fine with Android on all states (Open, Foreground/Background, Closed/Forced Quit). But not with iOS, which does not work when app is closed.

Everytime i close the app, force to open with a custom URL scheme, the app opens but the getInitialUri returns the uri as null, which is being called here:

main.dev

StreamSubscription uriSubscription;

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  @override
  void dispose() {
    if (uriSubscription != null) {
      uriSubscription.cancel();
    }
    super.dispose();
  }

  Future<void> initPlatformState() async {
    debugPrint('com.fonixtelematics.app: initPlatformState');
    // if (!mounted) return;
    if (uriSubscription != null) {
      uriSubscription.cancel();
    }

    await pushService.init();
    uriSubscription = await URILinks().initStream();

    await URILinks().checkInitialURI();
  }

urilinks.dart

class URILinks {
  Future<StreamSubscription> initStream() async {
    return getUriLinksStream().listen(uriLinksHandler);
  }

  Future<void> checkInitialURI() async {
    debugPrint('com.fonixtelematics.app: checkInitialURI');
    return getInitialUri().then(uriLinksHandler).catchError((e) {
      debugPrint(
          'com.fonixtelematics.app: checkInitialURI ERROR ' + e.toString());
      navigatorKey.currentState.pushNamed(Routes.main);
    });
  }

  void uriLinksHandler(Uri uri) {
    debugPrint('com.fonixtelematics.app: uriLinksHandler ' + uri.toString());
    if (uri != null) {
      debugPrint('com.fonixtelematics.app: uriLinksHandler ' + uri.host);
    }
    if (uri != null && uri.host != null && uri.host.isNotEmpty) {
      switch (uri.host) {
        case 'auth':
          ...
          break;
        case 'alert':
          ...
          break;
        default:
          navigatorKey.currentState.pushNamed(Routes.main);
          break;
      }
    } else {
      throw (false);
    }
  }
}

Is anyone else having the same issue?

andrefcferreira avatar Jan 23 '20 15:01 andrefcferreira

I had the same problem, did you solve it?

humeng avatar Mar 22 '20 08:03 humeng

Hi @andrefcferreira and @humeng,

I'm facing the same issue with getInitialLink / getInitialUri methods returning null. Did you find any solution?

@avioli, @bbedward, @ened, @wkornewald, @markathomas, @MisterJimson: I allow myself to also tag you on this issue too. ;)

For the others, be aware that this issue is the same as #47 and #22.

Thanks in advance for your response

toussam avatar Dec 29 '20 12:12 toussam

We are also facing the same issue. Please update here if you guys find any solution.

kssujithcj avatar May 20 '21 05:05 kssujithcj

i have same problem how to solve it please

osamamohammed98 avatar Jun 16 '21 14:06 osamamohammed98

hey Guys, any news?

MHabashy10 avatar Jul 13 '21 17:07 MHabashy10

I was facing the same issue when tapping a Push notification resulted in cold-starting the iOS application, I fixed it here #129

ritaamro avatar Aug 04 '21 14:08 ritaamro

@avioli hi, may I know are you still maintaining this plugin? Thanks!

tengyeekong avatar Sep 14 '21 09:09 tengyeekong