未收到Swift 5的Firebase云消息传递通知

问题描述 投票:0回答:1

我正在尝试从Firebase在我的项目中实现通知。我遵循了此处列出的所有步骤。但是,未发送测试消息。

https://firebase.google.com/docs/cloud-messaging/ios/certs

我已经在Apple Developer Account网站上完成了以下操作;

  1. 创建了身份验证密钥并将其添加到Google Firebase控制台
  2. 使用捆绑包ID创建了应用ID,并启用了推送通知
  3. [为IOS开发创建了配置文件。
  4. 然后在“签名和功能”下添加了此条款

我已经实现了以下代码;

通知类别

var apnsToken = Messaging.messaging().apnsToken

func registerNotifications() {
        if #available(iOS 10.0, *) {
            UNUserNotificationCenter.current().delegate = self
            Messaging.messaging().delegate = self
            let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
            UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { (isGranted, error) in
                if error != nil {
                    print(error as Any)
                    return
                } else {
                    switch isGranted {
                    case true:
                        DispatchQueue.main.async {
                            UIApplication.shared.registerForRemoteNotifications()
                        }
                    case false:
                        print("Not Granted")
                        return
                    }
                }
            }
        }
    }

    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
        let dataDict:[String: String] = ["fcmToken": fcmToken]
        NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
        FirestoreService.shared.didReceiveRegistrationToken(withFCMToken: fcmToken)
    }

AppDelegate

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        print("RESIGERED FOR REMOTE NOTIFICATIONS:", deviceToken)
        NotificationService.shared.apnsToken = deviceToken
    }

我已经确认我正在获取fcmToken,并且我也正在获取设备令牌数据。

但是,我没有收到任何通知。

一如既往的帮助,我们将不胜感激。

ios swift apple-push-notifications firebase-notifications
1个回答
0
投票

删除并重新安装了该应用程序,它可以正常工作。我不知道为什么。

© www.soinside.com 2019 - 2024. All rights reserved.