【发布时间】:2020-07-04 12:44:35
【问题描述】:
我使用 this 为 Flutter 实现了 Firebase 云消息传递。在 Android 中一切正常,但 iOS 推送通知仅在应用程序处于前台时显示。
请帮我在后台显示通知应用程序并终止。
这些是我到目前为止所做的步骤
- 创建了 firbase 项目。
- 将 GoogleService-Info.plist 添加到 xcode。
- 将 firebase_messaging: ^6.0.13 & flutter_local_notifications: ^1.3.0 添加到 pubspec.yaml 中。
-
在颤抖中
FirebaseMessaging firebaseMessaging = new FirebaseMessaging(); FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin(); @override void initState() { super.initState(); var android = new AndroidInitializationSettings('mipmap/ic_launcher'); var ios = new IOSInitializationSettings(); var platform = new InitializationSettings(android, ios); flutterLocalNotificationsPlugin.initialize(platform); firebaseMessaging.configure( onLaunch: (Map<String, dynamic> msg) async{ print(" onLaunch called ${(msg)}"); }, onResume: (Map<String, dynamic> msg) async{ print(" onResume called ${(msg)}"); }, onMessage: (Map<String, dynamic> msg) async{ showNotification(msg); print(" onMessage called ${(msg)}"); }, ); firebaseMessaging.requestNotificationPermissions( const IosNotificationSettings(sound: true, alert: true, badge: true)); firebaseMessaging.onIosSettingsRegistered .listen((IosNotificationSettings setting) { print('IOS Setting Registed'); }); firebaseMessaging.getToken().then((token) { update(token); }); getCashedInfo(); } showNotification(Map<String, dynamic> msg) async { var android = new AndroidNotificationDetails( 'sdffds dsffds', "CHANNLE NAME", "channelDescription", ); var iOS = new IOSNotificationDetails(); var platform = new NotificationDetails(android, iOS); await flutterLocalNotificationsPlugin.show( 0, "This is title", "this is demo", platform); } update(String token) { print(token); } -
我在 Xcode 中添加了
if #available(iOS 10.0, *) { UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate }
【问题讨论】:
-
那么,你找到答案了吗?
-
喂?你找到答案了吗?我也有同样的问题。
-
我猜不是。这个问题有几十个线程,没有任何记录的、可重复的更正。
-
有什么解决办法吗?我被这个困住了......
标签: flutter firebase-cloud-messaging