FCM - Send a notification to iOS device using expo (React native)

Viewed 3391

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 :

firebase project with APN keys

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.

2 Answers

You can use in this case expo eas build to build ios though you are using bare workflow project then eas will take care aboute all required configurations to run expo push notifications on ios

Related