0 Replies Latest reply on May 11, 2017 5:36 AM by fat_owl

    Phonegap app (PGB) fails sending push notification to ios with "invalid APN credentials."

    fat_owl

      config.xml

      <gap:plugin name=phonegap-plugin-push source=npm spec=1.9.4>

              <param name=SENDER_ID value=[from google api] />

      </gap:plugin>

       

      mypage.html

       

      var push = PushNotification.init({

            "android": {

              "senderID": "[from google api]"

            },"ios": {

              "gcmSandbox": "true",

              "alert": "true",

              "badge": "true",

              "sound": "true",

              "clearBadge": "true"

            },

            "browser": {

              "pushServiceURL": 'http://push.api.phonegap.com/v1/push'

            },

          });

         

           push.on('registration', function(data) {

           console.log(data.registrationId);

         

           document.getElementById("txt_deviceid").value = data.registrationId;

       

       

         

         

           });

       

       

           push.on('notification', function(data) {

           //alert(data.title+" Message: " +data.message);

           window.location.href="#/page1/page17";

           });

       

       

           push.on('error', function(e) {

           alert(e);

           });

       

       

      myserver.php(ios function)

       

      function sendPushIos($to,$title,$message)

        {

        define( 'API_ACCESS_KEY', 'AIzaSyDr1-xxxxxxxxxxxxxxxxxxmw');

        $registrationIds = array($to);

        $msg = array

        (

        'title' => $title,

        'body' => $message,

        'vibrate' => 1,

        'sound' => 1

       

        );

        $notification = array

        (

        'title' => $title,

        'body' => $message

       

        );

       

        $fields = array

        (

        'registration_ids' => $registrationIds,

        'notification' => $notification,

        'data' => $data,

        'priority' => 'high'

        );

        $headers = array

        (

        'Authorization: key=' . API_ACCESS_KEY,

        'Content-Type: application/json'

        );

        $ch = curl_init();

        curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );

        curl_setopt( $ch,CURLOPT_POST, true );

        curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );

        curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );

        curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );

        curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );

        $result = curl_exec($ch );

        curl_close( $ch );

        echo $result;

        }

       

       

      myserver.php(android)

      function sendPush($to,$title,$message)

        {

       

        define( 'API_ACCESS_KEY', 'AIzaSyDrxxxxxxxxxxxx6SwhKxQL39FeIKGmw');

        $registrationIds = array($to);

        $msg = array

        (

        'message' => $message,

        'title' => $title,

        'vibrate' => 1,

        'sound' => 1

       

       

        // you can also add images, additionalData

        );

        $fields = array

        (

        'registration_ids' => $registrationIds,

        'data' => $msg,

        'priority' => 'high'

        );

        $headers = array

        (

        'Authorization: key=' . API_ACCESS_KEY,

        'Content-Type: application/json'

        );

        $ch = curl_init();

        curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );

        curl_setopt( $ch,CURLOPT_POST, true );

        curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );

        curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );

        curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );

        curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );

        $result = curl_exec($ch );

        curl_close( $ch );

        echo $result;

        }

       

      generated app id, development certificate (with push notification services), .p12 file from it and a provisioning profile. built using PGB.

       

      Iam getting GCM android-like registrationID (same length) from my ios app.

      works in android. but throws "InvalidAPNcredentials" in ios10 iphone5.

       

      Please help.