Flutter Firebase消息传递 - iOS无声通知不在背景下启动应用程序以通过背景服务处理通知
在扑动日志中,将无线通知发送到设备时,下面的日志将出现在取消推动启动事件的情况下,以防止在后台启动应用程序以处理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)
}
}
in flutter logs , on sending a silent notification to the device the below log appears where push launch event is cancelled preventing app to be started in background to process the notification in fcm background service.
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>!
in main.dart file in the main function initializeFirebase function is
called .
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);
}
my appdelegate file
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)
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否包括这样的iOS许可请求
Have you included permission request like this for iOS