Right now I use loop to send bulk points, I want to send bulk push in ios, how can I send this without using loop.
Here is my code:
function sendToBulkIphone($artistID,$type="artist") {
$deviceToken = $this->deviceToken;
$message = $this->message;
$postid = $this->postid;
$notificationtype = $this->NotificationType;
$time = $this->time;
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushkey/artist_'.$artistID.'/ck_user_production.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', '1234'); STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
$body['title']="Notification";
$body['message']=$message;
$body['postid']=$postid;
$body['NotificationType']=$notificationtype;
$body['time']=$time;
for($n=0;$n<count($deviceToken); $n++) {
// Build the binary notification
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken[$n]). pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));//, strlen($msg)
if (!$result) {
$jsondata['message'] = 'Message not delivered';
$jsondata['status'] = 0;
}
else {
$jsondata['message'] = 'Message successfully delivered';
$jsondata['status'] = 1;
}
}
fclose($fp);
return true;
}
Can anyone please tell me how can I resolve this issue ?