Search code examples
flutterfirebasefirebase-cloud-messaging

Notifications permission pop-up will always appear in flutter app


I have been trying for days to get rid of Notifications Permission pop-up that appears in my Flutter app on first app run.

My code is the following:

void main() async {
  await Hive.initFlutter();
  runApp(MyApp());
}


class MyApp extends StatefulWidget {
  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    check_internet_connection();
    super.initState();
  }
    @override
    Widget build(BuildContext context) {
      return GetMaterialApp(
        title: 'Myapp',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Text('test')
      );
    }
}

In general, I am using firebase and firebase messaging in my app. While trying to disable the permission request, I wanted to see what causes the appearance of the pop-up window, hence I deleted almost everything (trial & error) from my main, leaving just the code above. I am still getting the notifications permissions request on my iOS real device.

In my pubspec.yaml I have this: firebase_messaging: ^11.1.0

How can I disable the pop-up?


Solution

  • I think I have found why I have this behaviour. It is because of my AppDelegate.swift file where I have added this:

    UNUserNotificationCenter.current().delegate = self
    
    let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
    UNUserNotificationCenter.current().requestAuthorization(
      options: authOptions,
      completionHandler: { _, _ in }
    )
    
    application.registerForRemoteNotifications()
    

    By removing the requestAuthorization() I don't get the pop-up anymore.