更新时间:2022-11-03 22:14:28
目前 Expo Apps 不支持 FCM for iOS Apps.
请注意,FCM 目前不适用于 Expo iOS 应用程序."->https://docs.expo.dev/push-notifications/using-fcm/
到目前为止,对于 iOS,您有 2 个选项:
调用 APN,信息在 链接你指出.
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 :
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 ...
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.
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:
Call APNs, the info is on the link you pointed out.