繁体   English   中英

如何将iPhone推送通知发送到多个设备?

[英]how to send iPhone Push Notification to Multiple Devices.?

我正在从数据库中获取设备令牌,但是通知已成功发送,它刚刚接收到数据库中的最新设备。

但是我的数据库中有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));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM