简体   繁体   中英

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?

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM