firebase-ios-sdk
firebase-ios-sdk copied to clipboard
Weird behavior when using retrieveFCMTokenforSenderID
[REQUIRED] Step 1: Describe your environment
- Xcode version: 13.4.1
- Firebase SDK version: 8.15
- Installation method:
CocoaPods
- Firebase Component: Messaging
- Target platform(s):
iOS
[REQUIRED] Step 2: Describe the problem
I'm trying to use the retrieveFCMTokenforSenderID to send a firebase message from other firebase project. So basically I have the Firebase project of the app itself, where the APNs token is set, and the Firebase project of the server, where ideally would not have the app.
But when I have this scenario, it's throwing the exception Unexpected HTTP response with status: 401 null, which it seems to be because of the APNs.
After I set the app on the server firebase project, with the APNs token, it started to work as expected. Even when I've deleted the app on the server firebase project, it continues to work, even for new devices (with different tokens).
Anyone knows if it's really necessary to set the app on the sender firebase project? On the firebase documentation it's not clear, and it sounds a little weird for me after removing the app from the sender firebase project the app continues to work
If it's not necessary, there is any other setting that I'm missing to be able to send messages through different firebase projects?
Steps to reproduce:
Try to send a push notification using the token generated by retrieveFCMTokenforSenderID for another firebase project.
Thanks for reaching out, @FranciscoPDNeto. Per checking, it's not necessary to configure an app in the second Firebase project. You only need to retrieve the token using the retrieveFCMTokenForSenderID
to make it work. You may check this guide for more info.
Thank you @rizafran for the answer, that was my thought too, but trying to send using this FCM token generated by this retrieveFCMTokenForSenderID
I received 401 null error, and it was solved just after I created the app in the second Firebase project, and even though after I delete the app in this second Firebase project, the sending messaging using this token kept working
@FranciscoPDNeto I suspect that the error code 401 you encountered is due to Authentication error according to the docs. With this, could you check if the token you're sending inside the Authentication header is the correct server key associated with your project? You may also check the validity of your server key by following this guide.
I suppose that I'm sending the right one, because when I try to send a message to the same project it works, and after I've created the app on the second firebase project it starts to work sending to this app, but I'll double check that again
Sorry for the delay, so we are using the Firebase Admin SDK for java to send the messages, and then we make the initialization of the Firebase app and we use the Firebase messaging on the startup and so we don't need to setup any server key on the authentication header. The send operation gives that 401 null error just when I try to send to the token generated by retrieveFCMTokenForSenderID
, token generated with the sender id of this server firebase project. When it's sending for token generated for the same sender id (on the same server firebase project) it works, and if I set a app inside the server firebase project and setup the APNs on this app, it starts to work (and keep working even if I remove the app after), does that make sense?
We have the same issue on our project. retrieveFCMTokenForSenderID doesn't work as expected