Open yatish3230 opened 3 years ago
I found the same issue.
On the firebase console, I'm able to push to all IOS devices, works fine. But when I target a specific device, using the token that comes from the onRegister
method, It won't deliver.
(edit) I've tried to call the Firebase endpoint directly:
curl --header "Content-Type: application/json" \
--header "Authorization: key=AA..." \
https://fcm.googleapis.com/fcm/send \
-d '{"notification": {"body": "Hello from curl via FCM!", "sound": "default"},
"priority": "high",
"to": "token..."}'
Error: InvalidRegistration (end edit)
APNS itself seems fine, as I'm able to push to a particular device by doing:
curl -v --header "apns-topic: $TOPIC" --header "apns-push-type: alert" \
--header "authorization: bearer $AUTHENTICATION_TOKEN" \
--data '{"aps":{"alert":"this works!"}}' \
--http2 https://${APNS_HOST_NAME}/3/device/${DEVICE_TOKEN}
Not totally related, but for those using SNS to push to Firebase, the endpoint gets disabled with the error:
"FailureMessage":"Platform token associated with the endpoint is not valid","FailureType":"InvalidPlatformToken"
I figured my issue.
The token that comes from onRegister
while on IOS has nothing to do with Firebase. It got confusing because when using the android counterpart to this lib that token works on Firebase straight away.
The token that comes on iOS works on APNS only, so you'll need to show Firebase the device-id from IOS and get a valid FCM registration token back. From the Google docs:
Using the Instance ID service's batchImport method, you can bulk import existing iOS APNs tokens to Google Cloud Messaging or Firebase Cloud Messaging, mapping them to valid registration tokens. Call the Instance ID service at this endpoint, providing a list of APNs tokens in the JSON body:
The api above will return a valid token that you can use to push to IOS devices from Firebase.
I still wonder why sending to multiple devices works, quite strange.
I am able to get notification from firebase if i target multiple device, but didn't get the notification if i want to trigger it for a particular device by using fcm token. Although i tried fcm token using Pusher and it did work. Can anyone help me what could be the possible thing that i am missing