Deep Links not Redirecting to Correct Screen on iOS - Flutter, GoRouter

604 Views Asked by At

The app I am working on (Android, iOS) uses go_router 12 for navigation and deep linking, but the latter seems to work only on Android devices. To be more precise, clicking on a link correctly redirects the user to the app in both cases, but on iOS only the screen that gets loaded is always the home page and not the page pointed to by the link.

I have correctly setup both Universal Links and a custom url scheme, proved by the fact that the links open the app, they just not redirect to the correct screen. I have checked go_router docs and other examples of deep linking with it and it seems it should supposedly work out of the box, with required setup basically only related to ios entitlements and AndroidManifest.

Does anybody know what could be the cause and help me troubleshoot? Thank you in advance

UPDATE 2024-02-01

Initially, using uni_links solved part of the problem with iOS, but deep links still didn't work as intended on iOS push notifications. It turns out that it was indeed a problem with the latter, which were handled via OneSignal and their flutter package one_signal_flutter. The issue is fixed by using the additionalData way of sending deep links via push notifications (see mobile push notifications | OneSignal docs) and after updating the OneSignal package to either:

Thank you everybody for trying to help

2

There are 2 best solutions below

2
On

If you have installed uni_links package previously, you may try to remove uni_links package, then flutter clean and flutter pub get again.

0
On

I've bumped into same problem, and I found ios won't bring the path into the app if you use deep link to open the app. So I use uni_link to capture path and push it manually.

This is my workaround method:

// You have to set your gorouter first.
// This will get full Uri when opening the app by deep link
// Android will directly go to the route you want, so don't neet to push manually.
Uri? uri = await getInitialUri();
if(uri != null && Platform.isIOS) {
  router.push(uri.path);
}

// This is for app staying in the background.
uriLinkStream.listen((uri) async {
  if(Platform.isIOS) { // ios won't bind the path
    router.push(uri!.path);
  }
});