Ionic 2 - Push not working for iOS


#1

Hello,

I have integrated push notifications in my ionic 2 application. But it only works for android, not for iOS. Below is my code which is i am using to register device.

    let push = Push.init({
              android: {
                senderID: "<senderID>"
              },
              ios: {
                alert: "true",
                badge: false,
                sound: "true"
              }
            });

        push.on('registration', (pushdata) => {
           console.log(pushdata.registrationId);
        });

I am getting registrationId for both ios and android device but when i am sending push then i am receiving on android but not on ios.

Below is my code in php:

<?php 
function send_notification($tokens)
{

    $url = 'https://fcm.googleapis.com/fcm/send';
    $priority="high";
    $notification= array('title' => 'Notification Title','body' => 'Notification content will show here' );

    $fields = array(
         'registration_ids' => $tokens,
         'notification' => $notification
        );

$server_key = 'AAAA8rswZD0:APA91bEklbPsR9tYd78DonUgFDzdgteZU4yzlXIJwjJPQlZ67NjJRv79OOsBhGigd9-8YRTrYPg_5xYNfTV3iYej3aKMXN0Wwtmgj26ohzLxwqyc1xTsy7LMFCJ09OsDmqq2R1HipHBuIVlCsSIbtK4fAgqZ31qVcQ';

    $headers = array(
        'Authorization:key='.$server_key,
        '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_SSL_VERIFYHOST, 0);  
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    // echo json_encode($fields);
   $result = curl_exec($ch);           
   echo curl_error($ch);
   if ($result === FALSE) {
       die('Curl failed: ' . curl_error($ch));
   }
   curl_close($ch);
   return $result;
}
$tokens = array('dhKd-W-kbJY:APA91bFKza0X8yuNDhyo51gPLwDuF7gmu_Z5sbHz4XjxfE6NSgv5xLVpbrGV8uBUGKMiHP6BK88zumJfixj6_xdqvm9kpCSlgNDwdcnbke7CQ-kfThB3AnUSvOppGAaB3VUmuW7u7Prc', '8739f5cc9ce84ee8314c48fc274e8d087ce38e8c49b583305363271885c4a491');

  $message_status = send_notification($tokens);
  echo $message_status;
?>

#2

This issue is fixed now.


#3

May I ask, how did you fix it?


#4

Used APNs Certificate