![](/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.