4

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.

Seba99
  • 1,197
  • 14
  • 38
  • From my experience using Expo, setting up notifications for iOS doesn't need FCM, I use FCM for android and non-expo projects. I run this cmd: expo build:ios -t archive and then let expo manage everything... Then I enable push notifications on app developer account. Then I test using expo notification tool. Android is a different story – jonson.ncube Sep 22 '21 at 19:12

2 Answers2

3

Currently FCM for iOS Apps is not supported on Expo Apps.

"Note that FCM is not currently available for Expo iOS apps." -> https://docs.expo.dev/push-notifications/using-fcm/

For iOS you have 2 options so far:

  1. Call APNs, the info is on the link you pointed out.

  2. Use Expo push notifications service

0

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

Ali Mohammad
  • 794
  • 9
  • 16