Firebase 云消息传递未收到通知 (iOS)

Jef*_*all 5 push-notification ios firebase swift firebase-cloud-messaging

我正在尝试使用 Firebase Notification Composer 向我的设备发送测试通知。我正在接收 FCM 令牌并将其打印到我的控制台,然后我尝试向该令牌发送通知。

这是我检查过的:

1) 我使用的是 iOS 12.4.1

2)我正在分配消息传递委托

3) 我从委托方法接收 FCM 令牌

4) 我已经确认通过打印到控制台启用了通知,当我被提示允许通知时,我点击了允许

5) 我已经验证在 Firebase 项目设置中有一个 APNs Auth Key 上传,具有正确的 TeamID 和 KeyID

6)当我发送测试消息时没有调用委托方法willPresentNotifications

7)我尝试过启用/禁用 Swizzling,但都不起作用

8)调试没有错误

这是代码:

import UIKit
import Firebase
import UserNotifications


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    UITabBar.appearance().barTintColor = UIColor(named: "Splish")!
    UINavigationBar.appearance().barTintColor = UIColor(named: "Splish")!
    UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]

    FirebaseApp.configure()

    Messaging.messaging().delegate = self

    UNUserNotificationCenter.current()
        .requestAuthorization(options: [.alert, .sound, .badge]) {granted, error in

            print("Permission granted: \(granted)")
    }

    UNUserNotificationCenter.current().delegate = self

    application.registerForRemoteNotifications()

    return true
}


func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {

    print("FCM Token Is: \(fcmToken)")
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

    print("Token is: \(deviceToken)")
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {

    print("Error is \(error)")
}
Run Code Online (Sandbox Code Playgroud)

Mr.*_*ity -1

对于使用 Swift 的 iOS 14.4,我在这里使用了 Firebase 的示例。

在 @C6Silver 建议在“功能”中启用“推送通知”的帮助下,我能够接收 fcm 测试通知。

大家编码愉快!