如何将iPhone推送通知发送到多个设备。
问题描述:
我正在从数据库中获取设备令牌,但发送成功的通知,它只是接收到数据库中的最新设备。如何将iPhone推送通知发送到多个设备。
但我的数据库中有3个设备令牌。
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'badge' => 1,
'sound' => 'default'
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$result = mysql_query("SELECT DeviceToken FROM iOS");
while($row = mysql_fetch_array($result))
{
$deviceToken=$row['DeviceToken'];
echo $deviceToken;
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
}
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered '.PHP_EOL;
// Close the connection to the server
fclose($fp);
echo "<script>alert('Notification Sent Successfuly!'); location.href='Pushnotification.php';</script>";
答
放在while循环
$result = fwrite($fp, $msg, strlen($msg));
“最新的设备” 是指这条线? – 2015-03-13 06:37:37
最新的设备意味着当应用程序安装在新的iPhone和我的数据库获取新的设备令牌,然后当我发送推送通知通知刚刚收到最新的设备令牌... – 2015-03-13 08:04:13