Closed KPS250 closed 4 years ago
You solved the problem? I have such a problem
To understand the root cause you need to understand that APNS uses two servers for push notifications- SandBox & Production. When you build a debug version of the app on the iOS device during development it connects to the SandBox server and retrieves token from it. Once you create a release build of the app, it will connect to the production server.
If you are testing the app with debug build then to test the notifications you need to ensure that you test it through sandbox. Once you receive the token you can use the below Google API to convert APNS token to FCM token(Use POSTMAN or any other HTTP Client) HTTP POST : https://iid.googleapis.com/iid/v1:batchImport HTTP HEADERS: Content-Type: application/json Authorization : key=YOUR_SERVER_KEY (Get this from FCM Console) BODY:
{
"application": "com.company.app", (YOUR_APP_PACKAGE)
"sandbox":true,
"apns_tokens":[
"7c6811bfa1e89c739c5862122aa7ab68fc4972dea7372242f74276a5326f...."
]
}
RESPONSE:
{
"results": [
{
"registration_token": "ejXQlECjCeI:APA91bE7oaUhaFnGyl77lFrySdEaWxocM0oj81uNezACX1wsZXiTyL4OYo5ssvFjjWYpFymMVyqBccboVcwTTW2rvykOmV_CABDM7rTIRCiJFl_9ngf7SrDSYoFouwNj69JSwlH.....",
"apns_token": "7c6811bfa1e89c739c5862122aa7ab68fc4972dea7372242f74276a5326f....",
"status": "OK"
}
]
}
Now use the registeration token from the response to test the notification using FCM API: HTTP POST: https://fcm.googleapis.com/fcm/send HTTP HEADERS: Content-Type: application/json Authorization : key=YOUR_SERVER_KEY BODY:
{
"to": "ejXQlECjCeI:APA91bE7oaUhaFnGyl77lFrySdEaWxocM0oj81uNezACX1wsZXiTyL4OYo5ssvFjjWYpFymMVyqBccboVcwTTW2rvykOmV_CABDM7rTIRCiJFl_9ngf7SrDSYoFouwNj69JSwlH.....",
"notification": {
"title": "Breaking News",
"body": "New Story available."
},
"priority":"high"
}
RESPONSE:
{
"multicast_id": 3564165249446719487,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "1576230576106890"
}
]
}
You will receive the notification. To test this with the release build just change the key "sandbox"=false while converting APNS to FCM token
TLDR You are using Sandbox APNS token and trying to send notification using Production APNS Server which is resulting into "InvalidRegistration**" error
Great...Its work for me
thank you...Its work for me
to be precise, authentication key is set as access token for authentication method oauth2 using postman
Thanks my kyng!
God bless you friend!
Thank you brother.It works for me.
{ "multicast_id": 534587200498972686, "success": 0, "failure": 1, "canonical_ids": 0, "results": [ { "error": "NotRegistered" } ] }
For Android, it's working fine but on iOS I am getting the token but while sending a notification with a token to the device it gives the error 'InvalidRegistration'