I'm trying to use GCM for IOS and Android clients. It seems to work fine with IOS when app is in the foreground, however, when the app is in the background, the notification center doesn't receive the message and didReceiveRemoteNotification with completionHandler
doesn't get called.
I identified a problem as a wrongly formatted message from GCM to APNS. Namely, that's how it looks:
[message: New message, collapse_key: do_not_collapse, from: **************]While, the IOS push notifications should have
aps
key in the notification, am I right ? As well as content-available set to 1. For example:
{ "aps" : { "content-available" : 1 }, "data-id" : 345 }
By the way, in the foreground app receives the message anyway, the problem is only with the background. Any advice on how should I approach a problem, to make GCM work for both ios and android?
UPDATE: That is what I found on the net:
Regarding actual communication, as long as the application is in the background on an iOS device, GCM uses APNS to send messages, the application behaving similarly as using Apple’s notification system. But when the app is active, GCM communicates directly with the app
So the message I received in the foreground mode:
[message: New message, collapse_key: do_not_collapse, from: **************]
Was the direct message from GCM(APNS did not participate in this affair at all). So the question is: does APNS reformat what GCM sends to it to adhere to ios notifications format? If so how do I know that APNS actually does something and whether it sends me a notification in different format ? Is there any way to view logs of incoming data from APNS ?
UPDATE: Okay, I managed to change the structure of the message and now in the foreground mode I receive the following message:
Notification received: ["aps": {"alert":"Simple message","content-available":1}, collapse_key: do_not_collapse, from: **************]
Now it seems to be well formatted, but there is still no reaction when the app is in the background. didReceiveRemoteNotifification completionHandler doesn't get called! What should I look for and where can a problem be ? Can the square bracket be a problem for push notification ? To be even more precise, ios doesn't post any alerts/badges/banners from that incoming notification.