Firebase云消息传递未接收通知(iOS) [英] Firebase Cloud Messaging Not Receiving Notification (iOS)

查看:48
本文介绍了Firebase云消息传递未接收通知(iOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use Firebase Notification Composer to send a test notification to my device. I am receiving an FCM token and printing it to my console, then I am trying to send a notification to that token.

这是我检查过的内容:

1)我在iOS 12.4.1上

1) I am on iOS 12.4.1

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

2) I am assigning the messaging delegate

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

3) I am receiving the FCM token from the delegate method

4)我已验证通过打印到控制台启用了通知,并且当系统提示我允许通知时,我单击了允许

4) I have verified that notifications are enabled through printing to console, and when I was prompted to allow notifications I clicked allow

5)我已经验证了Firebase项目设置中是否上传了APNs身份验证密钥,并带有正确的TeamID和KeyID

5) I have verified that in the Firebase project settings there is an APNs Auth Key uploaded, with a correct TeamID and KeyID

6)发送测试消息时未调用委托方法willPresentNotifications

6) The delegate method willPresentNotifications is not called when I send the test message

7)我已经尝试过启用/禁用Swizzling,但均无效

7) I have tried with Swizzling enabled/disabled, neither work

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的示例

For iOS 14.4 using Swift, I used Firebase's example here.

在@ C6Silver的帮助下,建议启用推送通知".在功能"中,我随后可以接收fcm测试通知.

With the help from @C6Silver suggesting to enable "Push Notifications" in Capabilities, I was then able to receive fcm test notifications.

祝大家编码愉快!

这篇关于Firebase云消息传递未接收通知(iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆