FCM topic - Cannot subscribe to topic: xxx with to

2019-04-17 22:26发布

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?

4条回答
时光不老,我们不散
2楼-- · 2019-04-17 23:15

In MessagingDelegate try it:

func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
    Messaging.messaging().subscribe(toTopic: "/topics/testTopic")
}
查看更多
家丑人穷心不美
3楼-- · 2019-04-17 23:17

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.

查看更多
等我变得足够好
4楼-- · 2019-04-17 23:20

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
}
查看更多
淡お忘
5楼-- · 2019-04-17 23:24

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()
查看更多
登录 后发表回答