I'm unable to send push notification to an iOS app created with Expo.io.
There's not a clear doc on how to do so so here are my trials and things I've done :
- First I've created my firebase project and setup it for iOS
- I've also read this -not that complete- guide to setup the POST call to FCM server
- I've added my APN push notification key to my firebase project
And before calling this endpoint programatically I'm trying to get it working (as I did in less than 1h for android) with POSTMAN
Here is what I'm calling :
method: POST
url : https://fcm.googleapis.com/fcm/send
body :
{
"to": "token (read about it at the end of the post",
"priority": "high",
"data": {
"experienceId": "@expoAccount/projectSlug",
"title": "Hello there",
"message": "General kenobi",
"content_available": true
},
"content_available": true
}
I've tested a lot of body different structures (with / whithout "content_available" key or with "notification" object ... Because all body structures are diffent from all the questions or docs I've read so far
So I'm not sur of the body I must send ... But If the notification works on Android it should work on iOS or I don't see the point of FCM ...
Talking about the token used for iOS
For iOS the token I'm getting from Notifications.getDevicePushTokenAsync()
(expo doc) isn't a valid FCM token because somehow it "connects" to some sandbox or whatever Apple call that shit behaviour.
Without this thread I would be lost in the void... So the token I use is the one I get after "transforming" the sandbox token to a "true" one calling the google api : https://iid.googleapis.com/iid/v1:batchImport
I'm sometimes facing some strange behaviour, especially when sending with the key "content_available": true
: The token seems to be "forced uneregistred".
Why I'm saying this ? Because on the first call the result is : "results": [{ "error": "InvalidRegistration" }],
and all the next calls answers are : "results": [{ "error": "NotRegistered" }],
and the batchImport generate a new token when called with the "sandboxToken" which doesn't change when I receive some success return (depending on that body structure) : "results": [{"message_id": "0:1632152120739230%37bf04f1f9fd7ecd"}],
Note: I've got some successfull return but no notification on the i-phone at all.