2015-03-13 169 views
0

我正在從數據庫中獲取設備令牌,但發送成功的通知,它只是接收到數據庫中的最新設備。如何將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>"; 
+0

「最新的設備」 是指這條線? – 2015-03-13 06:37:37

+0

最新的設備意味着當應用程序安裝在新的iPhone和我的數據庫獲取新的設備令牌,然後當我發送推送通知通知剛剛收到最新的設備令牌... – 2015-03-13 08:04:13

回答

0

放在while循環

$result = fwrite($fp, $msg, strlen($msg)); 
相關問題