<small id='tuijA'></small><noframes id='tuijA'>

<i id='tuijA'><tr id='tuijA'><dt id='tuijA'><q id='tuijA'><span id='tuijA'><b id='tuijA'><form id='tuijA'><ins id='tuijA'></ins><ul id='tuijA'></ul><sub id='tuijA'></sub></form><legend id='tuijA'></legend><bdo id='tuijA'><pre id='tuijA'><center id='tuijA'></center></pre></bdo></b><th id='tuijA'></th></span></q></dt></tr></i><div id='tuijA'><tfoot id='tuijA'></tfoot><dl id='tuijA'><fieldset id='tuijA'></fieldset></dl></div>

    1. <tfoot id='tuijA'></tfoot>

      <legend id='tuijA'><style id='tuijA'><dir id='tuijA'><q id='tuijA'></q></dir></style></legend>

          <bdo id='tuijA'></bdo><ul id='tuijA'></ul>

        带有 FCM 令牌的设备的 Firebase 通知说已发送但未收到

        时间:2023-07-29
          <tbody id='zvwky'></tbody>
        <tfoot id='zvwky'></tfoot>

            <i id='zvwky'><tr id='zvwky'><dt id='zvwky'><q id='zvwky'><span id='zvwky'><b id='zvwky'><form id='zvwky'><ins id='zvwky'></ins><ul id='zvwky'></ul><sub id='zvwky'></sub></form><legend id='zvwky'></legend><bdo id='zvwky'><pre id='zvwky'><center id='zvwky'></center></pre></bdo></b><th id='zvwky'></th></span></q></dt></tr></i><div id='zvwky'><tfoot id='zvwky'></tfoot><dl id='zvwky'><fieldset id='zvwky'></fieldset></dl></div>

              <small id='zvwky'></small><noframes id='zvwky'>

            • <legend id='zvwky'><style id='zvwky'><dir id='zvwky'><q id='zvwky'></q></dir></style></legend>

                <bdo id='zvwky'></bdo><ul id='zvwky'></ul>

                  本文介绍了带有 FCM 令牌的设备的 Firebase 通知说已发送但未收到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 FCM 令牌从 firebase 通知控制台向特定设备发送一个简单的推送通知.firebase 通知控制台将通知显示为已发送,但设备未收到通知.我已尝试发送通知,然后等待查看控制台是否从 didReceiveRemoteNotification 记录日志,但通知需要很长时间(数小时)才能显示为在 firebase 控制台中发送(即使我设置了优先级)到high).

                  I am attempting to send a simple push notification from the firebase notification console to a specific device using an FCM token. The firebase notification console shows the notification as sent but the device does not receive it. I have tried sending the notification and then waiting to see if the console logs from didReceiveRemoteNotification, but the notification takes too long (hours) to be shown as sent in the firebase console (even when I set the priority to high).

                  应用代理

                  import UIKit
                  import Firebase
                  import FirebaseStorage
                  import FirebaseDatabase
                  import FirebaseMessaging
                  import CoreData
                  import UserNotifications
                  
                  @UIApplicationMain
                  class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
                  
                      var window: UIWindow?
                  
                      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
                          // Override point for customization after application launch.
                  
                          // Use Firebase library to configure APIs
                          FirebaseApp.configure()
                  
                          /////
                          // For Firebase Cloud Messaging (FCM)
                          if #available(iOS 10.0, *) {
                              // For iOS 10 display notification (sent via APNS)
                              UNUserNotificationCenter.current().delegate = self
                              let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
                              UNUserNotificationCenter.current().requestAuthorization(
                                  options: authOptions,
                                  completionHandler: {_, _ in })
                          } else {
                              let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
                              application.registerUserNotificationSettings(settings)
                          }
                          application.registerForRemoteNotifications()
                          // End of [for Firebase Cloud Messaging (FCM)]
                          /////
                  
                          return true
                      }
                  
                      ///////////////////////
                      // FCM Setup
                  
                      // Monitor token generation for FCM: Be notified whenever the FCM token is updated
                      func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
                          print("Firebase registration token: (fcmToken)")
                      }
                  
                      // Monitor token generation for FCM:
                      func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
                          Messaging.messaging().apnsToken = deviceToken
                      }    // Handle messages received through the FCM APNs interface
                      func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
                          print("didReceiveRemoteNotification")
                          // If you are receiving a notification message while your app is in the background,
                          // this callback will not be fired till the user taps on the notification launching the application.
                          // TODO: Handle data of notification
                  
                          // With swizzling disabled you must let Messaging know about the message, for Analytics
                          // Messaging.messaging().appDidReceiveMessage(userInfo)
                  
                          // Print message ID.
                          // gcm_message_id
                          if let messageID = userInfo["gcmMessageIDKey"] {
                              print("Message ID: (messageID)")
                          }
                  

                  ^我的猜测是问题可能与gcm_message_id"/gcmMessageId"/gcm.message_id"有关,因为我在下面尝试的三种方法中的每一种都不同

                          // Print full message.
                          print(userInfo)
                      }
                  
                      // Handle messages received through the FCM APNs interface
                      func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
                          print("didReceiveRemoteNotification (withCompletionHandeler)")
                          // If you are receiving a notification message while your app is in the background,
                          // this callback will not be fired till the user taps on the notification launching the application.
                          // TODO: Handle data of notification
                  
                          // With swizzling disabled you must let Messaging know about the message, for Analytics
                          // Messaging.messaging().appDidReceiveMessage(userInfo)
                  
                          // Print message ID.
                          if let messageID = userInfo["gcmMessageIDKey"] {
                              print("Message ID: (messageID)")
                          }
                  

                  ^我的猜测是问题可能与gcm_message_id"/gcmMessageId"/gcm.message_id"有关,因为我在下面尝试的三种方法中的每一种都不同

                          // Print full message.
                          print(userInfo)
                  
                          completionHandler(UIBackgroundFetchResult.newData)
                      }
                  
                      // End of [FCM Setup]
                      ///////////////////////
                  }
                  

                  视图控制器

                  class ViewController: UIViewController {
                  
                      override func viewDidLoad() {
                          super.viewDidLoad()
                  
                          // Retrieve the current registration token for Firebase Cloud Messaging (FCM)
                          let token = Messaging.messaging().fcmToken
                          print("FCM token: (token ?? "")")
                        }
                  }
                  

                  权利和启用推送通知

                  我已添加推送权利 并启用了推送通知的后台模式 并将 GoogleService-Info.plist 添加到我的项目中.

                  I have added the push entitlements and enabled background modes for push notifications and added the GoogleService-Info.plist to my project.

                  通知发送方法

                  我正在从 Firebase 通知控制台(如下所示)创建通知,因此通知本身的结构应该没有问题.

                  I am creating notification from the Firebase Notifications console (as shown below) so there should be no issue with the structure of the notification itself.

                  我尝试了以下方法来解决这个问题,但都产生了相同的结果:

                  I have tried the following approaches to remedy the issue, but all have produced the same result:

                  • Google Firebase 文档
                  • 带 firebase 教程的远程通知
                  • Google Firebase 快速入门

                  有谁知道为什么通知在 firebase 通知控制台中被标记为已发送但未显示在设备上?

                  推荐答案

                  我在处理推送通知时使用的几个故障排除步骤是:

                  A couple of troubleshooting steps I use when working with push notifications are:

                  1. 首先让推送工作独立于 Firebase 服务.我使用这个 工具.
                  2. 确保您没有任何包标识符命名空间冲突.因此,例如在设备上拥有 appstore 构建、testflight 构建和/或开发应用程序构建的任意组合.删除除一个应用程序之外的所有实例.捆绑标识符是您的设备如何知道将推送通知路由到哪个应用程序的方式.
                  3. 当所有其他方法都失败时 - 我尝试通过构建一个新的示例项目并将其连接到一个新的 firebase 项目来隔离问题,看看我是否可以将注意力集中在能够在没有任何其他业务的情况下进行推送工作我的应用程序中的逻辑.这有助于我向自己证明我并没有发疯,并向我证明这不是某种神秘的网络状况导致了我的困境.

                  我希望这可以帮助您在工作时搞清楚.

                  I hope this helps you as you work get it all figured out.

                  这篇关于带有 FCM 令牌的设备的 Firebase 通知说已发送但未收到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在前台收到的关于 Firebase 通知的开放活动 下一篇:如何向特定的 Android 用户组发送 Firebase 推送通知

                  相关文章

                1. <tfoot id='H5iCy'></tfoot>

                    <legend id='H5iCy'><style id='H5iCy'><dir id='H5iCy'><q id='H5iCy'></q></dir></style></legend>
                      <i id='H5iCy'><tr id='H5iCy'><dt id='H5iCy'><q id='H5iCy'><span id='H5iCy'><b id='H5iCy'><form id='H5iCy'><ins id='H5iCy'></ins><ul id='H5iCy'></ul><sub id='H5iCy'></sub></form><legend id='H5iCy'></legend><bdo id='H5iCy'><pre id='H5iCy'><center id='H5iCy'></center></pre></bdo></b><th id='H5iCy'></th></span></q></dt></tr></i><div id='H5iCy'><tfoot id='H5iCy'></tfoot><dl id='H5iCy'><fieldset id='H5iCy'></fieldset></dl></div>
                    1. <small id='H5iCy'></small><noframes id='H5iCy'>

                        <bdo id='H5iCy'></bdo><ul id='H5iCy'></ul>