skip to Main Content

My deep links on iOS aren’t working correctly (I followed the official Flutter guide on how to implement deep links). On Android, everything works perfectly fine, but on iOS (when the app is killed), the app just launches from the link but stays at the home page (doesn’t navigate to the correct route).

I use auto_route for routing.

This is my routerDelegate in MaterialApp.router:

          routerDelegate: _appRouter.delegate(
            deepLinkBuilder: (deepLink) {
              if (RegExp(r'/oferta/[^/]+/[^/]+.*$')
                  .hasMatch(deepLink.path)) {
                return deepLink;
              } else {
                return DeepLink.defaultPath;
              }
            },
          ),

2

Answers


    1. If it is working in android devices, you need to check permission in the ‘info.plist’ file.
    2. deep-linking often does not work with virtual devices(simulators), so please try to use real devices.
    Login or Signup to reply.
  1. First, when dealing with deep links on iOS, it’s essential to make sure you’ve set up the necessary configurations in your Xcode project. Here are some steps to follow:

    URL Types in Info.plist: Ensure that your app’s Info.plist file has the URL Types configured correctly. You need to specify the URL scheme for your app, which should match the one you use in your deep links.

    • Open the Info.plist file.
    • Add a new "URL Types" key if it doesn’t already exist.
    • Add an item under "URL Types" and set your URL scheme.

    Associated Domains: If your deep links involve domains (like https://example.com/deeplink), you need to set up Associated Domains in Xcode. This step is important for Universal Links, which are a more reliable way of handling deep links.

    Example:

    import 'package:flutter/material.dart';
    import 'package:uni_links/uni_links.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: MyHomePage(),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      @override
      void initState() {
        super.initState();
        initUniLinks();
      }
    
      void initUniLinks() async {
        try {
          final initialLink = await getInitialLink();
          handleDeepLink(initialLink);
        } on Exception {
          // Handle any exceptions
        }
    
        linkStream.listen((String? link) {
          if (link != null) {
            handleDeepLink(link);
          }
        });
      }
    
      void handleDeepLink(String link) {
        // Handle your deep link here
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          // Your app's content
        );
      }
    }
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search