FCM topic - Cannot subscribe to topic: xxx with token: (null) - iOS

≡放荡痞女 提交于 2019-12-22 01:13:23

问题


I'm getting this error from Firebase Messaging API:

[Firebase/Messaging][I-FCM002010] Cannot subscribe to topic: /topics/testTopic with token: (null)

But before:

Messaging.messaging().subscribe(toTopic: "/topics/testTopic")

I'm printing out the token like this:

print("TOKEN: \(InstanceID.instanceID().token() ?? "NO TOKEN")")

The result is:

TOKEN:cXPhGQ_inE4:APA91bEKZF5depHmIm9gDliCFRCRcnJf5LYy5FMg6nhpWvKU3o3HEtr1WTBHUiCZXT4XzhVg2oqXzhtfrgf83brtLdqXii546644ciMPO80tri4JPueQBClKbaomEfoh54ku8E2lw

So the token isn't null.

Am I doing something wrong? Anyone some help?


回答1:


The problem was that I wanted to subscribe in didFinishLaunchingWithOptions but in that point not all services were set up. The solution was to subscribe in the delegate didRegisterUserNotificationSettings.




回答2:


In MessagingDelegate try it:

func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
    Messaging.messaging().subscribe(toTopic: "/topics/testTopic")
}



回答3:


I had similar problem. The solution was to invoke FirebaseApp.configure() first:

FirebaseApp.configure()
Messaging.messaging().delegate = self

instead of:

Messaging.messaging().delegate = self // this brakes FCM
FirebaseApp.configure()



回答4:


The most ideal place to resolve this issue is in the MessagingDelegate method didRefreshRegistrationToken.

func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
   // TODO: subscribe to topics here
}


来源:https://stackoverflow.com/questions/44524660/fcm-topic-cannot-subscribe-to-topic-xxx-with-token-null-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!