Quickstart-ios: Can't subscribe to topic

Created on 7 Nov 2016  Â·  53Comments  Â·  Source: firebase/quickstart-ios

I'm trying to subscribe to a topic using the following code (from device):

func connectToFcm() {
    FIRMessaging.messaging().connectWithCompletion { (error) in
        if (error != nil) {
            print("Unable to connect with FCM. \(error)")
        } else {
            print("Connected to FCM.")
            FIRMessaging.messaging().subscribeToTopic("/topics/default-notifications-channel")
        }
    }
}

The debugger shows the following message:

<FIRMessaging/WARNING> Failed to subscribe to topic Error Domain=com.google.fcm Code=5 "(null)"

I can receive device targeted notifications so APNS configuration is working correctly.

Using Firebase (3.8.0)
Using FirebaseAnalytics (3.5.1)
Using FirebaseCore (3.4.4)
Using FirebaseInstanceID (1.0.8)
Using FirebaseMessaging (1.2.1)

Any ideas? Thank you!

Most helpful comment

As an update: we have identified the issue and have a solution, we are working on getting it published ASAP, I will update here as soon as it is available. Sorry for the delay!

All 53 comments

Same here. Registering multiple tropics at once.

I have the same issue with registering multiple topics. Always:

2016-11-09 11:22:52.106: Failed to subscribe to topic Error Domain=com.google.fcm Code=5 "(null)"

Yes, same here. Looping through the topics results in errors. As in https://github.com/firebase/quickstart-ios/issues/8 - which is not fixed even though it is closed. I have tried putting 1 second delay between the calls (far from optimal), but even then some of the subscribe calls fail. It would be also great to have callbacks from the subscribeToTopic and unsubscribeFromTopic methods..

Hi All, we are looking into the issues when subscribing to many topics.

Also when subscribing to topics from the iOS SDK you should not prepend the topic name with /topics/ just use the topic name.

Hi @kroikie, thanks for your insight.

The problem occurs even when subscribing to a unique topic. On the other hand, if I subscribe to topics from iOS without prepending the topic name with /topics/ I get the following runtime warning (for a topic called default-notifications-channel):

2016-11-10 09:18:44.562: <FIRMessaging/WARNING> WARNING. Topic name default-notifications-channel should be prefixed with /topics/ as /topics/default-notifications-channel

Thank you!

@sendoa you are correct, sorry, currently the iOS SDK does currently require the /topics/ prefix.

As for the topic subscriptions failing, they should be retried automatically. Have you tried adding a delay between subscriptions as suggested by @olegdynamo?

@kroikie the problem occurs even when subscribing to a single topic.

Thank you!

I have the same issue. Anyone have solution?

We're having the exact same issue, and multi-topic subscriptions is very important to us.

Any news?

Multi-topic subscriptions is very important to anyone!

@sendoa If you are seeing the same error when subscribing to a single topic I would suggest you file a support ticket at firebase.google.com/support since I'm not able to reporduce that. Maybe with more information we can get to the bottom of it. Please identify me in the request so that it can be directed to me.

@all: The issue of subscribing to multiple topics is known and we are implementing a fix. Implementing a delay between subscriptions should help in the mean time.

Hi @kroikie , when are you going to release the fix? Do you have estimation time?

A delay workaround is ok only in theory, in real world it can't be done because you can't know how long the delay should be. Looking forward for the fix.

same problem here

Why is Google ignoring us??

@All I apologize for the delay in resolving this issue.

As an update: We have identified the issue and a fix is in the works and will be released soon.

@kroikie do you have news about this issue?

My workaround was a delay between subscriptions.

@kroikie Have the fixed version already released?
I can not found it on here https://firebase.google.com/support/release-notes/ios

@kroikie Is there any progress?

Any news?

@kroikie It's been over two months since you said you guys were looking into it. This is a pretty big issue with the SDK and its reliability. What's going on?

As an update: we have identified the issue and have a solution, we are working on getting it published ASAP, I will update here as soon as it is available. Sorry for the delay!

i am seeing the same behavior on droid using

compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'

any news about fixing it on android sdk
?
regards

Could you take a look at the inconsistency in the /topic prefix while you're at it? The latest iOS SDK documentation says

The name of the topic, for example "sports".

For the first argument. However, if one supplies "sports", the console complains that it is not prefixed with "/topics/".

It works when it looks like this:
FIRMessaging.messaging().subscribe(toTopic: "/topics/myTopic")

It does not work without /topics/ prefixed.
This inconsistency is very confusing.

Also, may I suggest creating a method for subscribing to multiple topics, such as:

var myTopics = ["/topics/1", "/topics/2", "/topics/3"]
FIRMessaging.messaging().subscribeToTopics(myTopics)

It's cleaner and should make it easier for you guys to program all the subscriptions into one HTTP request.

Hi!
I'm using version FirebaseMessaging (1.2.1) for ios, and I also have this errors in console.
But I tried to send messages via curl, and it works fine.
Seems like this is just artifact messages, like when sdk tries to send subscription request when previous is failed. Is this possible?

3.13 seems to address this issue. Diego commented on my question here: http://stackoverflow.com/questions/42233474/firebase-clear-cached-subscriptions-after-delete (which was also entirely resolved by this update).

I saw the same error when I try to subscribe to only one topic. After that I tried it in the didRegisternotificationSettings: method and error gone. If you use static topic names, you can try this. When I sent notification to that topic, it succeeded.

func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
let topicName = "/topics/news"
FIRMessaging.messaging().subscribe(toTopic: topicName)
}

I hope this helps somebody else.

@nfinfu What notification do you send and from where?

@nickdnk I used postman (chrome extension to make http request) and configuration is same with firebase documents.

Header values:
Content-Type: application/json
Authorization: key=YOUR_SERVER_KEY

Request body:
{
"to" : "/topics/news",
"data": {
"link" : "www.google.com"
},
"notification" : {
"body" : "body string",
"title" : "title string"
}
}

I meant what UNNotification do you send to didRegister? In Swift.

From: nfinfu notifications@github.com
Reply-To: firebase/quickstart-ios reply@reply.github.com
Date: Friday, 17 February 2017 at 14.54
To: firebase/quickstart-ios quickstart-ios@noreply.github.com
Cc: "[email protected]" nickdnk@hotmail.com, Mention mention@noreply.github.com
Subject: Re: [firebase/quickstart-ios] Can't subscribe to topic (#146)

@nickdnkhttps://github.com/nickdnk I used postman (chrome extension to make http request) and configuration is same with firebase documents.

Header values:
Content-Type: application/json
Authorization: key=YOUR_SERVER_KEY

Request body:
{
"to" : "/topics/news",
"data": {
"link" : "www.google.com"
},
"notification" : {
"body" : "body string",
"title" : "title string"
}
}

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/firebase/quickstart-ios/issues/146#issuecomment-280655322, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIBYss0f_AnCyMrB3x2LFTP84fZvMFHCks5rdaaogaJpZM4KrAAF.

@nickdnk I did not use UNNotification, I used this configuration to take notification request in didFinishLaunchingWithOptions method:

let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)

    application.registerForRemoteNotifications()

didRegister notificationSettings: is the applicationDelegate methods which invoke when you make a notification request like above.

But that's not different than waiting a bit, since didRegister returns immediately if a token exists.

Are you sure that it's not just fixed because you updated to the latest version of the SDK? (3.13). As I posted the error has been fixed.

I installed the sdk today and when i try to subscribe i saw the error on console. After move the code into didregister, error gone.

On 17 Åžub 2017 17:16 +0300, nickdnk notifications@github.com, wrote:
>

But that's not different than waiting a bit, since didRegister returns immediately if a token exists.

Are you sure that it's not just fixed because you updated to the latest version of the SDK? (3.13). As I posted the error has been fixed.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub (https://github.com/firebase/quickstart-ios/issues/146#issuecomment-280660948), or mute the thread (https://github.com/notifications/unsubscribe-auth/ASq4aRTBFSnVzK-Meu61NxeHZXagmwRkks5rdavLgaJpZM4KrAAF).

Odd. Are you sure you have the 3.13 version installed as Pod? In your Podfile.lock I mean. I changed nothing other than updating. I even deleted the app from my device entirely and reinstalled to verify that it was actually fixed. Haven't seen the error since. I don't use didRegister for anything other than:

FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: .sandbox) // or .prod

This is the my podfile.lock content:

  • Firebase/Core (3.12.0):
  • Firebase/Messaging (3.12.0):

I don't understand why pod installed the previous version.

Try doing

pod clean
pod install

And make sure you don't have a specific version set in your Podfile :)

Sent from my iPhone

On 17 Feb 2017, at 20.26, nfinfu <[email protected]notifications@github.com> wrote:

This is the my podfile.lock content:

  • Firebase/Core (3.12.0):
  • Firebase/Messaging (3.12.0):

I don't understand why pod installed the previous version.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/firebase/quickstart-ios/issues/146#issuecomment-280743292, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIBYsiqkzKMnT4pX0whdF7OgSkhnbMg5ks5rdfRhgaJpZM4KrAAF.

I am using the Firebase Unity SDK.
Topic works well for AOS but not for iOS Topic.
In iOS, if send a bundle, you will receive a notification. If send it to Topic, it will not be received.

Can not subscribe to topic: / topics / * with token: (null)
like this

Firebase-unity version : 3.0.1
Unity version : 5.5.1f

Getting the same issue here when subscribing to single or multiple topics on iOS. Any updates?

If you're still having trouble subscribing to topics? What is your Firebase Messaging SDK version? I'd _highly_ recommend you upgrade to FirebaseMessaging 2.x (part of Firebase 4.x released at Google I/O. If not able to get to FirebaseMessaging 2.x, at least try and get to the latest 1.x version, as it has some bug fixes around topic subscription.

@rsattar Still seeing these issues. For every subscription the following gets logged to the console in xCode:

[Firebase/Messaging][I-FCM004001] Failed to subscribe to topic Error Domain=com.google.fcm Code=0 "(null)"

With logging set to Max, this is what gets logged:

[Firebase/Messaging][I-FCM017000] Topic subscription request: sender=<hidden token>&app=<hidden app>&device=<hidden device>&app_ver=3.0.11&X-gcm.topic=/topics/articles&X-scope=/topics/articles
[Firebase/Performance][I-PRF100009] Recording network trace: https://iid.googleapis.com/iid/register
[Firebase/Messaging][I-FCM017002] Invalid registration request, response
[Firebase/Messaging][I-FCM004001] Failed to subscribe to topic Error Domain=com.google.fcm Code=0 "(null)"

Try adding this to your Info.plist:

<key>CFBundleURLTypes</key>
<array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>com.google.fcm</string>
            </array>
        </dict>
</array>

@rdelrosario Hmm, that should not make any difference, as FCM doesn't do anything with URL Schemes.

@naftaly When during app start are you subscribing to a topic? Typically you want to subscribe when you know you have a token from FCM. Also, if you set shouldEstablishDirectChannel to true, are you seeing any errors in the Xcode console for that? The direct channel is unrelated to topics, but failure to connect to that would suggest a possible problem.

@rsattar I subscribe whenever the FIRMessaging system tells me theres a new FCM token, so usually a bit after startup. Definitely past didFinshLaunching. Not seeing anything related to shouldEstablishDirectChannel in the console but then again I'm not sure what to look for and FIR outputs a lot of stuff when in debug logging mode.

@rsattar Not sure this is 100% relevant, but it definitely seems so. The sender from the registration request seems to be the FCM token. If I use that same token and try and send a message through the firebase console, the result says that token is not registered.

screen shot 2017-08-11 at 3 37 16 pm

It appears that all I needed to do was delete the app from my phone then reinstall and everything started working correctly.

Thanks for the detailed info @naftaly! I'm glad it's working now after an app reinstall. That suggests a possible bug in what was stored (either the Instance ID itself, or the token). Was there any change to the app's bundle ID, app version, the GoogleService-Info.plist, or anything else between builds of your app?

@rsattar the version was bumped. Can’t think of anything else.

IS SOLVED for
[Firebase/Messaging][I-FCM002010] Cannot subscribe to topic: /topics/news with token: (null)
I had this problem too. After many attempts, I reached a solution.
You must run the subscription topic code after the firebase token send operation.
FIRMessaging.messaging().subscribeToTopic("news")
For example,
I pulled out the json data and started the subscription after fill the table.

Hey all,

This issue has grown long enough that it's become hard to find help for individual errors within this large thread. If you're still struggling with this issue, please open a new issue with the version of Firebase Messaging you're using, the code you're using to integrate Messaging, and any error messages that appear in console.

Hi,

for me, it was an error between the bundle identifier in Xcode and my firebase configuration.

Hi all ,
I am getting issue Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"

var myTopics = "all";
this.fcm.subscribeToTopic(myTopics).then(success => {
console.log("Here is success"+success); alert(success) },
error => { console.log("
This is the issue**"+error); alert(error);})
.catch(response => {
alert(response);
console.error('Gists error = ', response);
});

Was this page helpful?
0 / 5 - 0 ratings

Related issues

myflashlab picture myflashlab  Â·  7Comments

sundarsan picture sundarsan  Â·  3Comments

Shingyien picture Shingyien  Â·  5Comments

bakeddean picture bakeddean  Â·  6Comments

abdulKarim002 picture abdulKarim002  Â·  6Comments