ios FCM令牌不调用didReceiveRegistrationToken

bfnvny8b  于 2023-10-21  发布在  iOS
关注(0)|答案(3)|浏览(139)

你好,在我的应用程序中使用FCM
当我试图读取FCM令牌时,即使编译器不调用此委托方法,也是任何方式,请帮助。
当我把休息和检查这个方法是不调用我使用ios11 swift4

extension AppDelegate: MessagingDelegate{

    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
        print("Firebase registration token: \(fcmToken)")

        let dataDict:[String: String] = ["token": fcmToken]
        NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
        // TODO: If necessary send token to application server.
        // Note: This callback is fired at each app startup and whenever a new token is generated.
    }

    func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
        print("Message data:", remoteMessage.appData)
    }  
}
uujelgoq

uujelgoq1#

didReceiveRegistrationToken

是一个委托函数。它将在从Firebase接收令牌时被调用。如果它没有被调用,请确保在AppDelegate中有以下代码

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
    Messaging.messaging().delegate = self
    return true
}

使用Messaging.messaging().delegate = self,我们注册AppDelegate以接收来自Firebase的方法调用

cpjpxq1n

cpjpxq1n2#

我使用下面的功能,它工作正常

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        if let refreshedToken = InstanceID.instanceID().token() {
           print("InstanceID token: \(refreshedToken)")
        }
    }
kxe2p93d

kxe2p93d3#

如果之前的token被更新,则调用“didReceiveRegistrationToken”,否则每次调用“didRegisterForRemoteNotificationsWithDeviceToken”,直到token更新。

相关问题