Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Messaging Cannot parse topic name

I'm trying to subscribe to a topic in my iOS app, but keep getting the error:

<FIRMessaging/WARNING> Cannot parse topic name /topics/pets/cnlLksAxmdYPkDjEftDwZjFwvDw2_coffee. Will not subscribe.

The code I'm trying to subscribe with is this:

FIRMessaging.messaging().subscribe(toTopic: "/topics/pets/\(name)")

where name is the last part of the topic you see in the error.

Does anybody know what I'm doing wrong? I've already confirmed Firebase messaging is correctly receiving notifications and all.

like image 766
MarksCode Avatar asked Mar 28 '17 00:03

MarksCode


1 Answers

The / character is not an allowed character for a topic name.

Characters allowed are:

  • a-z
  • A-Z
  • 0-9
  • -, _, ., ~, %

I can confirm these are the only allowed characters by testing in Android with a topic name of pets/123asd and the logs shown:

Invalid topic name: Pets/123asd does not match the allowed format [a-zA-Z0-9-_.~%]{1,900}

For iOS, the prefix /topics/ is needed and is still valid. The invalid characters only apply to the topic name you include after the prefix.

like image 81
AL. Avatar answered Oct 23 '22 21:10

AL.