skip to Main Content

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?

3

Answers


  1. Chosen as BEST ANSWER

    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.


  2. Faz answer helped me!! Additionally if you are using flutter_local_notifications plugin then you have to explicitly set it up to not to ask for permission by following way

    final DarwinInitializationSettings initializationSettingsDarwin =
          DarwinInitializationSettings(
        requestSoundPermission: false,
        requestBadgePermission: false,
        requestAlertPermission: false,
        onDidReceiveLocalNotification: onDidReceiveLocalNotification,
      );
    

    For more information, please see this stackoverflow post and this issue along with this part of the readme.

    Login or Signup to reply.
  3. In my case it was due to Flutter Badges. I was clearing firebase notification badges during app startup which in turn was requesting access to notifications

    https://pub.dev/packages/badges

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search