簡體   English   中英

Firebase 雲消息未收到通知 (iOS)

[英]Firebase Cloud Messaging Not Receiving Notification (iOS)

我正在嘗試使用 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)")
}

對於使用 Swift 的 iOS 14.4,我在這里使用了 Firebase 的示例。

在@C6Silver 的幫助下建議在功能中啟用“推送通知”,然后我能夠接收 fcm 測試通知。

祝大家編碼愉快!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM