flutter firebase messaging - ios静音通知,不在后台启动应用程序,通过后台服务处理通知.&



在flutter日志中,当向设备发送静音通知时,会出现以下日志,其中推送启动事件被取消,阻止应用程序在后台启动以在FCM后台服务中处理通知。

Dispatching low priority message: <xpc object>
<private> Delivering message from apsd: <private> 1020306858 <private>
<private> responding with an ack for message with guid <private>
<private> making delegate (<private>) calls to deliver message 1020306858 <private> for topic <private>
<private> calling <private> connection:didReceiveIncomingMessage:
<private> returned from <private> connection:didReceiveIncomingMessage:
Received incoming message on topic network.talker.app.dev at priority 1
Looking up connection on peer: 11431c0   found <private>
<private> informed that <private> acknowledges incoming message with guid <private>
<private> Removing incoming message with guid <private>
<private> _schedulePendingWorkUpdate
APSMessageStore - APSIncomingMessageRecordDeleteMessageForGUID <private>
Received remote notification request F1E6-BBE1 [ hasAlertContent: 0, hasSound: 0 hasBadge: 0 hasContentAvailable: 1 hasMutableContent: 0 ]
Deliver push notification F1E6-BBE1
Request DUET delivers content-available push notification to application
SUBMITTING: <private>
Not delivering user visible notification F1E6-BBE1 because it has no alert, sound or badge
Not delivering user visible push notification F1E6-BBE1 [ error=Error Domain=UNErrorDomain Code=1401 "Notification has no user visible content" UserInfo={NSLocalizedDescription=Notification has no user visible content} ]
Submitted Activity: com.apple.pushLaunch.{{bundle id}} at priority 5 <private>
Push not allowed for <private>
Daemon Canceling Activities: {(
com.apple.pushLaunch.{{bundle id}}
)}
CANCELED: com.apple.pushLaunch.{{bundle id}} at priority 5 <private>!

在主要。main函数中的dart文件initializeFirebase函数是调用。


Future initializeFirebase() async {
await Firebase.initializeApp();
NotificationSettings settings = await 
FirebaseMessaging.instance.requestPermission(
announcement: true,
carPlay: true,
criticalAlert: true,
);
FirebaseMessaging.onBackgroundMessage(
_onAppInTerminatedNotificationHandler, // This Callback must be static
);
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
}
Future<void> _onAppInTerminatedNotificationHandler(
RemoteMessage message,
) async {
await Firebase.initializeApp();
print('A new terminated Push Notification Received');
await NotificationManager.instance.showLocalNotification(message);
}

我的appdelegate文件

import UIKit
import Flutter
import FirebaseMessaging
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
}

是否包含了这样的iOS权限请求

NotificationSettings settings =
await FirebaseMessaging.instance.requestPermission(
announcement: true,
carPlay: true,
criticalAlert: true,
);

最新更新