I'm trying to send push notifications to my iOS app with GCM. The app doesn't get the notification when it's in the background but it does when it's in the foreground. I was testing the push notifications with a PHP script also which sends the message directly to the APNS and it's working in the background.
The JSON sent to GCM: (I'm sending it from a rest client for testing)
{
"to" : "token...",
"notification" : {
"title": "GCM TITLE",
"body" : "FROM GCM",
"badge": "1",
"sound": "default"
}
}
Not working: The userInfo received from GCM in didReceiveRemoteNotification:
Notification received: [aps: {
alert = {
body = "FROM GCM";
title = "GCM TILE";
};
badge = 1;
sound = default;
}, gcm.message_id: 123...]
Working: The userInfo received when sent from the PHP script (I also added the message_id to the JSON to see if that's the problem)
Notification received: [aps: {
alert = {
body = "FROM PHP";
title = "PHP TITLE";
};
badge = 2;
sound = default;
}, gcm.message_id: 123...]
I tried adding content_available to the JSON with different combinations but didn't help, the Content-Type and Authorization request headers are also set:
Content-Type:application/json
Authorization:key=...