title: Making GCM work for iOS device in the background
body: <p>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 <code>didReceiveRemoteNotification with completionHandler</code> doesn't get called.</p>
  
  <p>I identified a problem as a wrongly formatted message from GCM to APNS. Namely, that's how it looks: <pre>
  [message: New message, collapse_key: do_not_collapse, from: **************]</pre>
  While, the IOS push notifications should have <code>aps</code> key in the notification, am I right ? As well as content-available set to 1. For example:</p>
  
  <p>{
      "aps" : {
          "content-available" : 1
      },
      "data-id" : 345
  }</p>
  
  <p>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?</p>
  
  <p><strong>UPDATE</strong>:
  That is what I found on the net:</p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>So the message I received in the foreground mode:</p>
  
  <blockquote>
    <p>[message: New message, collapse_key: do_not_collapse, from: **************]</p>
  </blockquote>
  
  <p>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 ?</p>
  
  <p><strong>UPDATE:</strong>
  Okay, I managed to change the structure of the message and now in the foreground mode I receive the following message:</p>
  
  <blockquote>
    <p>Notification received: ["aps": {"alert":"Simple message","content-available":1}, collapse_key: do_not_collapse, from: **************]</p>
  </blockquote>
  
  <p>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.</p>