question

brett avatar image
brett asked

FCM ios push notifications aren't working (android does) for Unity

When first setting up Push Notifications, I started with Android.

I added the Google server API key to my title Settings section, created the project on the Firebase console, added an app for the google play id, and downloaded the google-services.json and added it to my Unity Assets folder.

I followed the instructions here for a client side c# script: https://firebase.google.com/docs/cloud-messaging/unity/client

I tested it, worked like a charm, no problems at all.

Next I wanted to set up ios... I created my .p12 certificate for the project / Mac Book I was using, then converted it to a .cen file using this: openssl pkcs12 -in apns-dev-cert.p12 -out apns-dev-cert.pem -nodes -clcerts

Right away the request for ios push notification request was returning an error in xcode telling me that my token I am passing in was too long, and couldn't go past a certain limit (I forget the exact error, but can bring it up if that will help).

So after doing some digging, I found this: https://api.playfab.com/docs/tutorials/landing-players/push-notification-basics/push-notifications-for-ios

It says to convert the byte array to a string... request.DeviceToken = System.BitConverter.ToString(token).Replace("-", "").ToLower();

Since I already had a string, but PlayFab wants it in a certain format, I attempted to first convert the token FCM gave me back to a byte array, then parse it the way PlayFab likes it:

pushToken = System.BitConverter.ToString(Encoding.ASCII.GetBytes(pushToken)).Replace("-", "").ToLower();

This seemed to have worked client side, I get the response that the end point was registered successfully, and when I look at my PlayFab dashboard, it shows an end point under my player. So I clicked to test sending the endpoint a push, and although it behaves as though the push was sent, I never received it on my client app.

I thought it was a glitch, so I try sending another push test, and this time it says I need to enter a number for 'Badge (number greater than zero)'. So I throw in some random int, like 1 or 2, etc.

This time the push fails, and it tells me the client unregistered the endpoint... even though I didn't touch the client app in any way, shape, or form.

At this point, I was advised by a friend not to use FCM, but just to follow the instructions here:

https://api.playfab.com/docs/tutorials/landing-players/push-notification-basics/push-notifications-for-ios

So I do, and I get the same results... the end point is registered, but when I try to sent a push test, the client never gets it, and the second attempt fails with the same error.

Then I get desperate, and think that I could just request pushes as an android, since I'm using a FCM token, PlayFab shouldn't care if the platform is ios or an apk, but this didn't work either.

So after double and triple checking all my work, I'm posting here to see if there is something I am missing, or if there is perhaps an issue on PlayFabs back end...

Android is still working like a charm.

unity3dPush Notifications
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brett avatar image brett commented ·

Also, I forgot to mention it above, but I created a second app in fcm console for ios, and downloaded my GoogleService-Info.plist and added it to the projects Assets folders. I was going to edit the initial post, but only saw a button to edit the title / tags.

0 Likes 0 ·
brendan avatar image
brendan answered

Yes, we can't support using FCM on iOS currently, as that's not tested in our Push system. To see if this is due to the FCM setup attempt, can you try creating a new Title ID, setting it up for iOS specifically using the APNS or APNS_SANDBOX certificate info, and see if Push works on it in your game?

6 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brett avatar image brett commented ·

I'll create a test project today and see what happens. Is there an eta for when PlayFab WILL support FCM for ios? It was super easy to install and set up, I think I just have to send you a token, and you need to accommodate the format / endpoint. I mean... isn't it almost identical to supporting it for Android?

If FCM is the problem, it's going to be a huge pain in the rear to clean out all the references to it from the project and xcode, I'm not even sure it would be possible (ios isn't my native dev platform).

I'm also skeptical to see how using FCM for Android, but NOT using it for ios is going to work, since it auto-installs so many things. I guess I'll find out when I build a new project from scratch. Perhaps if I just remove the ios app from my Firebase account it will help...

0 Likes 0 ·
brendan avatar image brendan brett commented ·

I would expect it to be straightforward, but assuming so before reviewing the details would inevitably mean it's not. We don't have a date for support of FCM Push to iOS right now, but we've got a backlog item tracking it.

But I'm not referring to all references to FCM throughout your project - just the FCM Push to iOS. The rest shouldn't have any impact.

0 Likes 0 ·
brett avatar image brett commented ·

I created a new project and had the same results.

I reached out to an associate, who has both ios and apk push notifications working through FCM for a title he's working on, and he showed me a way to handle them through a cloud script.

This bypasses the current PlayFab limitation, and has worked great. It took a little setup, but was worth it.

0 Likes 0 ·
brett avatar image brett commented ·

I'm working on another contract, and having to implement push notifications for both Android and ios again. Has there been any progress testing FCM with ios in your push system?

Is there a solution? If I use FCM for Android, what is my choice for ios? As soon as I pull the repo on my mac book, and open unity, it auto installs all the FCM classes.

When is PlayFab going to get on board and support this? If you don't plan to support it, when can I expect a fix for the current situation?

Essentially, you're telling me if I want to use FCM for Android, I'm screwed for ios, and there's nothing you or I can do about it... I have yet to see a solution PlayFab has provided.

0 Likes 0 ·
brendan avatar image brendan brett commented ·

The simple reality of it is that when you install FCM, it overrides the push receiver, and does not work with native iOS-formatted messages. If a) the FCM plugin could accept the native iOS Push format, or b) it gave you a way to have it in your project (for your Android SKU) without stealing the messages on the iOS SKU, there wouldn't be a problem. Unfortunately, we cannot change the way the FCM plugin behaves. And since our Push messages must use the native message format for each platform, that's not something we can easily work around.

For now, I would recommend either having two projects - one for iOS and one for Android, or else using https://fcm.googleapis.com/fcm/send in Cloud Script for your Push messages.

0 Likes 0 ·
Jeff Posey avatar image Jeff Posey brendan commented ·

I am the latest to fall victim to this. I thought that PlayFab messaging through Firebase FCM was supposed to be a cross-platform solution.

The iOS client receives notifications I send using Firebase just fine, but not from PlayFab. The registration using the deviceToken byte array works fine and the PlayFabClientAPI.RegisterForIOSPushNotification call succeeds.

Is that function even useful if it's not working? Is it still used to register if you send notifications with cloud scripts?

Could you elaborate a bit on the suggested workarounds? Thanks.

"For now, I would recommend either having two projects - one for iOS and one for Android, or else using https://fcm.googleapis.com/fcm/send in Cloud Script for your Push messages."

1 Like 1 ·
rob avatar image
rob answered

I have the exact same problem, two years later. I took exactly the same steps, tried to use Firebase at first, worked fine on Android. Then found I couldn't use the same token on iOS. So I followed the tutorial to set it up the recommended way and got rid of the Firebase stuff, removed the iOS app from Firebase console.

I'm now able to get a successful registration and am able to send push notifications with no errors but they never come through. Eventually it gives the error "iOS Push Notification Failed: Client has been unregistered for push notifications."

Tried deleting the player in PlayFab and starting with a new account, same problem.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

franklinchen avatar image franklinchen commented ·

Hi @rob @dejarajs, may I ask what kind of APNS cert you are using? If you are using XCode to build test app and deploy on your device, if ensure you are using the SANDBOX cert. After that, if your app have been registered via didRegisterForRemoteNotificationsWithDeviceToken call, using the device token to register PlayFab iOS push notification via RegisterForIOSPushNotification, then you can send the test notification with a template in player overview page. Let me know your setting and environment if it's still not working.

0 Likes 0 ·
dejarajs avatar image
dejarajs answered

any luck here? It looks like a lot of people having issues implementing push notifications for iOS. The notifications never reach the device.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Shivaprasad avatar image
Shivaprasad answered

@Brendan Bump

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image brendan commented ·

Nothing has changed from what's stated above. If we make any changes to support FCM, that would be reflected in our release notes, at a minimum (and there might be a blog post about it). If your question isn't FCM-specific, please open a new thread with the details, and our support team will be able to help you.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.