![](/img/trans.png)
[英]Flutter : Google Login pop up wont appear to select an account
[英]Notifications permission pop-up will always appear in flutter app
几天来,我一直在尝试摆脱在我的 Flutter 应用程序首次运行时出现的通知权限弹出窗口。
我的代码如下:
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')
);
}
}
一般来说,我在我的应用程序中使用 firebase 和 firebase 消息。 在尝试禁用权限请求时,我想看看是什么原因导致弹出窗口 window 的出现,因此我从我的 main 中删除了几乎所有内容(试错),只留下上面的代码。 我仍然在我的 iOS 真实设备上收到通知权限请求。
在我的 pubspec.yaml 我有这个:firebase_messaging: ^11.1.0
如何禁用弹出窗口?
我想我已经找到了为什么我有这种行为。 这是因为我在 AppDelegate.swift 文件中添加了以下内容:
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: { _, _ in }
)
application.registerForRemoteNotifications()
通过删除 requestAuthorization() 我不会再看到弹出窗口了。
Faz 的回答帮助了我!! 此外,如果您使用的是 flutter_local_notifications 插件,则必须明确将其设置为不通过以下方式请求许可
final DarwinInitializationSettings initializationSettingsDarwin =
DarwinInitializationSettings(
requestSoundPermission: false,
requestBadgePermission: false,
requestAlertPermission: false,
onDidReceiveLocalNotification: onDidReceiveLocalNotification,
);
有关详细信息,请参阅此 stackoverflow 帖子和此问题以及自述文件的这一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.