示例#1
0
 public function sendIosNotification($devices, $data)
 {
     foreach ($devices as $deviceToken) {
         $body['aps'] = array('badge' => 1, 'alert' => $data, 'sound' => 'default');
         $apns = new Apns();
         $apns->sendAppleNotification($deviceToken, $body);
     }
 }
示例#2
0
function send_ios_push2($user_id, $title, $message, $type)
{
    if ($type == 'walker') {
        include_once 'ios_push/walker/apns.php';
    } else {
        include_once 'ios_push/apns.php';
    }
    $msg = array("alert" => "" . $title, "status" => "success", "title" => $title, "message" => $message, "badge" => 1, "sound" => "default");
    if (!isset($user_id) || empty($user_id)) {
        $deviceTokens = array();
    } else {
        /* here not required to make it array, it's already an array. If we assign it as an array then it will be array in array and it will not work while it pass to apns file. */
        /* to check whether it is array or variable then you can uncomment all echo's from apns files
            now from http://54.148.195.44/test we can get the push to our company's device as I had made changes.
           */
        $deviceTokens = $user_id;
    }
    $apns = new Apns();
    $apns->send_notification($deviceTokens, $msg);
}
示例#3
0
function send_ios_push($user_id, $title, $message)
{
    include_once 'ios_push/apns.php';
    /* normally we have to send three perameters to ios device which are "alert","badge","sound", if it is not in aps{} object then push will not deliver.
       * in this array just add that veriable which's text in to "alert" you want to display in device screen as a notification
       * "status" is my strategy to display success or Filear or push data
       * "title" is a string which is send as a push string and i hed put it in this perameter because if ios developer wants that message then ios developer can get it from here
       * "messsage" is a bulk of data which is send from database
       *
       * don't concat title & message in alert if not required.
       *
       * if you want ot check the json will be proper or not then you can echo "$payload" variable which is generated in "apns.php"
       * and if you git is as a perfect json then only push data is perfect and may be send to device.
       *
       * i use "may" word in my sentence because if you hed made any mistake like devicetoken will not array if dubble jsonencode or etc then also it will not work.
       *
       * if in push you will not send perfect json then also it will not deliver to device
       * EXAMPLE of perfect json for ios push (formate taken from your "create_request" code. and also I put a comment in it. after formated array)
       *
        {
        "aps":{
        "alert":"message",
        "title":"title",
        "badge":1,
        "sound":"default",
        "message":{
        "unique_id":1,
        "request_id":2,
        "time_left_to_respond":"12 minutes",
        "request_data":{
        "owner":{
        "name":"first name last name",
        "picture":"picture",
        "phone":"+919876543210",
        "address":"address",
        "latitude":"22",
        "longitude":"77",
        "rating":1,
        "num_rating":1
        },
        "dog":{
        "name":"dog_name",
        "age":"dog_age",
        "breed":"dog_breed",
        "likes":"dog_likes",
        "picture":"dog_image"
        }
        }
        }
        }
        }
       */
    $msg = array("alert" => $title, "status" => "success", "title" => $title, "message" => $message, "badge" => 1, "sound" => "default");
    if (!isset($user_id) || empty($user_id)) {
        $deviceTokens = array();
    } else {
        $deviceTokens = array(trim($user_id));
    }
    $apns = new Apns();
    $apns->send_notification($deviceTokens, $msg);
}