Skip to content

iOS plugin blocks Firebase Messaging (FCM) deep links #200

@FilipeOS

Description

@FilipeOS

🐛 Bug Summary
When using the app_links plugin in a Flutter app together with firebase_messaging, push notifications that contain deep links (in the payload data['link']) fail to open or trigger any navigation on iOS. This issue does not occur on Android.

🔍 What Happens
When opening the app it show black screen and crash with:

let methodChannel = FlutterMethodChannel(name: "com.llfbandit.app_links/messages", binaryMessenger: registrar.messenger())

I get EXC_BAD_ACCESS

any advise?

Future<void> main() async {
  // Preserve the splash screen until the initialization is complete
  WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
  FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);

  final themeNotifier = ThemeNotifier();
  await themeNotifier.loadTheme();
  Get.put<ThemeNotifier>(themeNotifier);

  try {
    final appLinks = AppLinks();
    appLinks.uriLinkStream.listen((Uri? uri) {
      if (uri != null) {
        DeepLinkManager.instance.setPendingUri(uri);
        Get.offAll(() => const MainScreen());
      }
    });
  } catch (e) {
    //
  }

  try {
    await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    );
    FirebaseAnalytics analytics = FirebaseAnalytics.instance;
    analytics.setAnalyticsCollectionEnabled(true);
    //print("Firebase initialized with platform options.");

    if (!kIsWeb) {
      if (defaultTargetPlatform == TargetPlatform.android) {
        initFirebasePush();
        FirebaseMessaging.onBackgroundMessage(_firebaseBackgroundHandler);
      } else if (defaultTargetPlatform == TargetPlatform.iOS) {
        final deviceInfo = DeviceInfoPlugin();
        final iosInfo = await deviceInfo.iosInfo;
        if (iosInfo.isPhysicalDevice) {
          initFirebasePush();
          FirebaseMessaging.onBackgroundMessage(_firebaseBackgroundHandler);
        }
      }
    }
  } catch (e) {
    //print("Firebase initialization failed with options: $e");

    if (!kIsWeb) {
      try {
        await Firebase.initializeApp();
        //print("Retried Firebase initialization without options.");
      } catch (retryError) {
        //print("Firebase re-initialization failed: $retryError");
      }
    }
  }

  // Initialize Hive for persistent storage
  await Hive.initFlutter();

  _initializeProviders();

  // Run the main app
  runApp(App());

  // Remove the splash screen once initialization is complete
  FlutterNativeSplash.remove();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions