IOS GCM push notifications not received in background using PHP sender and Swift -


i'm working on getting background notifications work on ios gcm - non-background notifications working. here steps integrate background notifications:

  1. enable remote-notifications tag in uibackgroundmodes
  2. add content-available key notification payload.
  3. write application:didrecieveremotenotification:fetchcompletionhandler: in delegate.

here code delegate function:

func application( application: uiapplication,     didreceiveremotenotification userinfo: [nsobject : anyobject],     fetchcompletionhandler handler: (uibackgroundfetchresult) -> void) {         println("notification received2: \(userinfo)")          gcmservice.sharedinstance().appdidreceivemessage(userinfo);          nsnotificationcenter.defaultcenter().postnotificationname(messagekey, object: nil,             userinfo: userinfo)         handler(uibackgroundfetchresult.nodata);     } 

this code on-server php script:

<?php $regid = $_get["regid"]; $message = $_get["message"];  $data = array( 'price' => $message, 'sound' => 'default', 'body' => 'helloworld', 'title' => 'default', 'badge' => 12, 'content-available' => 1);  $ids = array( $regid);  sendgooglecloudmessage(  $data, $ids );  function sendgooglecloudmessage( $data, $ids ) {      $apikey = the-api-key-that-i-am-using;      $url = 'https://android.googleapis.com/gcm/send';      $post = array(                 'registration_ids'  => $ids,                 'data'              => $data,                 'content-available' => 1,     );      $headers = array(                     'authorization: key=' . $apikey,                     'content-type: application/json'                 );      $ch = curl_init();      curl_setopt( $ch, curlopt_url, $url );      curl_setopt( $ch, curlopt_post, true );      curl_setopt( $ch, curlopt_httpheader, $headers );      curl_setopt( $ch, curlopt_returntransfer, true );      curl_setopt( $ch, curlopt_postfields, json_encode( $post ) );      $result = curl_exec( $ch );      if ( curl_errno( $ch ) )     {         echo 'gcm error: ' . curl_error( $ch );     }      curl_close( $ch );      echo $result; } ?> 

i have tried sending content-available flag through both inner "data" array , outer "post" array, have indicated adding both.

the message not received fetchcompletionhandler function, rather waits until app active again , received normal application:didrecieveremotenotification function. reason notification not received via background functionality?

you should provide content_available gcm, not content-available (like in apns) , able receive push notifications in background.

https://developers.google.com/cloud-messaging/server-ref#send-downstream

p.s. - less 5 minutes ago had absolutely same problem. should read docs more carefully...


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -