简体   繁体   English

FCM令牌不要调用didReceiveRegistrationToken

[英]FCM token don't call didReceiveRegistrationToken

Hi using FCM into my application. 嗨,在我的应用程序中使用FCM

When I am trying to read FCM token even compiler don't call this delegate method also is any way please help. 当我尝试读取FCM令牌时,即使编译器也不调用此委托方法,也请以任何方式提供帮助。

when I put breaks and check this method is don't call I using ios11 swift4 当我休息一下并检查此方法是否不使用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)
    }  
}
 didReceiveRegistrationToken

is a delegate function. 是一个委托函数。 it will get called upon receiving token form firebase. 它将在收到令牌形式的Firebase时被调用。 if it's not getting called make sure you've following code in AppDelegate 如果未调用,请确保您已遵循AppDelegate中的代码

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

with Messaging.messaging().delegate = self we are registering AppDelegate for receiving the method call from Firebase 使用Messaging.messaging().delegate = self我们正在注册AppDelegate以接收来自Firebase的方法调用

I using the following function it is working fine 我使用以下功能正常工作

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM