flutter – Deep Links not working in iOS (App is opening but the link is not available) but working fine in Android


I am using the Dynamic Linking and Deep Linking in my e-Commerce Application.
The Deep Links when clicked on the Android Devices are working fine and showing the intended behaviour.
But when the same link is clicked on the iOS App, the App gets opened successfully, but the links which is clicked is not available in the function.

Previously I was using the below code for listening the Deep Links and Dynamic Links:

In main.dart file:

Future<void> initUniLinks() async {
    try {
      // Changes to implement the Dynamic Linking Functionality.
      PendingDynamicLinkData? initialLink = await FirebaseDynamicLinks.instance.getInitialLink();
      if (initialLink == null) {
        debugPrint('No Dynamic URI');
        final uri = await getInitialUri();
        if (uri == null) {
          debugPrint('no initial uri');
        } else {
          debugPrint("Deeplink URL ${uri.toString()}");
          CommonEntities.deeplinkURL = uri;
        }
      } else {
        debugPrint("Dynamic URL ${initialLink.link.toString()}");
        CommonEntities.deeplinkURL = initialLink.link;
      }
    } on PlatformException {
      // Platform messages may fail but we ignore the exception
      debugPrint('failed to get initial uri');
    } on FormatException {
      // FormatException will be thrown if the link was not the correct format
      debugPrint('malformed initial uri');
    }
  }

In home_screen.dart:

Future<void> initUniLinks() async {
    // BOC to check whether there is any Dynamic Link CLicked or not.
    FirebaseDynamicLinks.instance.onLink.listen((dynamicLinkData) {
      debugPrint("DynamicLink URL ${dynamicLinkData.link.toString()}");
      _callApiToPerformDeepLinking(dynamicLinkData.link.toString()); // Function to call the API to handle the Deep Link
    }).onError((error) {
      debugPrint(error.toString());
    });
  }

Then I found that we need to listen the links in the iOS App using the “uriLinkStream.listen”, so theI had to update the code of my home_screen.dart file and now the updated code is as follows:

Future<void> initUniLinks() async {
    bool _isDynamicLinkFound = false;
    // BOC to check whether there is any Dynamic Link CLicked or not.
    FirebaseDynamicLinks.instance.onLink.listen((dynamicLinkData) {
      debugPrint("DynamicLink URL ${dynamicLinkData.link.toString()}");
      _isDynamicLinkFound = true;
      _callApiToPerformDeepLinking(dynamicLinkData.link.toString()); // Function to call the API to handle the Deep Link
    }).onError((error) {
      debugPrint(error.toString());
    });
    // BOC to check for deeplink is available or not if no Dynamic Link is available.
    if (!_isDynamicLinkFound) {
      // Attach a listener to the stream
      uriLinkStream.listen((Uri? uri) {
        debugPrint("DeepLink URL ${uri.toString()}");
        _callApiToPerformDeepLinking(uri.toString());
      }, onError: (err) {
        debugPrint(err.toString());
      });
    }
  }

After applying the above change, not the app is opening when clicking the links, but the link which is clicked is not available in any of the functions of both files.

So is there anyone can please help me to figure out the missing link?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img