Flutter Firebase消息传递 - iOS无声通知不在背景下启动应用程序以通过背景服务处理通知

发布于 2025-02-05 03:45:25 字数 3642 浏览 2 评论 0原文

在扑动日志中,将无线通知发送到设备时,下面的日志将出现在取消推动启动事件的情况下,以防止在后台启动应用程序以处理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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万人眼中万个我 2025-02-12 03:45:25

您是否包括这样的iOS许可请求

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

Have you included permission request like this for iOS

NotificationSettings settings =
    await FirebaseMessaging.instance.requestPermission(
  announcement: true,
  carPlay: true,
  criticalAlert: true,
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文