DEV Community

George Ikwegbu Chinedu
George Ikwegbu Chinedu

Posted on

flutter iOS app is stuck on launchScreen when installed on real device πŸš€πŸš€πŸš€πŸš€

NB: This is going to be a really short article πŸ₯ΉπŸ₯Ή.

While working on my application with my team, we noticed our app was stuck on the splash screen, though this wasn't happening across all devices, as some ios devices went past the splash screen while some were simply stuck.
Β 
This even made apple to reject our submission on the basis of Performance - App Completeness.

To keep this short, make sure that all your functions in your main.dart is working well. In my own case, the culprit was my setupNotification() where I handled my pushNotification.

This required me to get the firebase token and also subscribe the device to a topic.

Well, this was where my headache started. I had gone forward to subscribe the device to a topic, which was causing the problem. The painful part was that I didn't get log on my IDE. Luckily for me I was able to see the exception from my firebase crashlytics.

Apparently, I needed to request for the APNSToken for iOS before I can subscribe to the topic.

final FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance;

  if (Platform.isIOS) {
      String? apnsToken = await _firebaseMessaging.getAPNSToken();
      if (apnsToken != null) {
        try {
          await _firebaseMessaging.subscribeToTopic('notificationChannel');
        } on FirebaseException catch (e) {
          debugPrint("George here is the error: $e");
        }
      } else {
        await Future<void>.delayed(const Duration(seconds: 3));
        apnsToken = await _firebaseMessaging.getAPNSToken();
        if (apnsToken != null) {
          try {
            await _firebaseMessaging.subscribeToTopic('notificationChannel');
          } on FirebaseException catch (e) {
            debugPrint("George here is the error: $e");
          }
        }
      }
    } else {
      try {
        await _firebaseMessaging.subscribeToTopic('notificationChannel');
      } on FirebaseException catch (e) {
        debugPrint("George here is the error: $e");
      }
    }
Enter fullscreen mode Exit fullscreen mode

This way, the error was corrected.

NB: Just trace the functions you have running in your main that might be throwing an error.

Thanks...

Top comments (0)