I am doing push notification in my project through GCM. My Application is able to receive notification in foreground but not in background.
I receive a message insi
Create notification in this pattern
{
"to": "ID",
"notification": {
"sound": "default",
"title": "TITLE",
"body": "BODY"
},
"priority": "high"
}
For ones who are dealing with Pushy instead of GSM, pushy's completion handler might not get called when app is in background because of this:
Even though you configure notification payload with propriate keys and values such as for example:
{"to":"device***Token", "data": {"message": "Hello World!"}, "notification": {"title": "test", "body": "my message"}, "content_available": true}
and send it using Pushy's Console, it happens that all these data are placed in pushy's site field: 'NOTIFICATION DATA'. So using Console we found no way to send: true, for key: "content_available" which is necceserry to involve handler when app is in background.
You can get out of this by using Postman for instance, configuring your request as this:
And in body place something you need to send, for example:
{"data":{"message": "Hello World!"},"tokens":["device***Token"],"content_available": true}
With this, you'll place "content_available" key inside "aps" and not inside "data", which will call your handler while app is in background.
use this payload
{
"aps": {
"alert": "Hello World",
"sound": "default"
"content-available" :1
}
}
With content-available enabled:
1 App is in Foreground
No system alert shown
application:didReceiveRemoteNotification:fetchCompletionHandler:
is called
2 App is in Background
System alert is shown
application:didReceiveRemoteNotification:fetchCompletionHandler:
is called
3App is in Suspended
App state changes to Background
System alert is shown
application:didReceiveRemoteNotification:fetchCompletionHandler:
is called
4 App is Not Running because killed by user
System alert is shown
No callback is called