如果我发送到的设备数量为 2,则以下代码可以正常工作 - 即它们都收到推送通知。但是,如果我将该限制提高到 100,则不会收到推送通知。
我已经阅读了这一点,看起来我正在正确发送批处理通知(即,通过单个连接的多个请求);连接的超时设置很好并且很高(60 秒);代码的输出看起来都井井有条;apache错误日志中没有任何内容,所以我看不出问题出在哪里。
我的客户真的被黑了。有人可以帮忙吗??
函数 sendIosPushes() {
$payload['aps'] = array('alert' => pushMessage, 'badge' => badgeNumber, 'sound' => 'default');
$payload = json_encode($payload);
//$statement = "SELECT * FROM push_ios WHERE device_token = 'device token of my iphone" OR device_token = 'device token of my ipod'; //works selecting my two devices from table
$statement = "SELECT * FROM push_ios"; //doesn't work when selecting all devices from table
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', apnsCert);
$connectTimeout = 60;
$apns = stream_socket_client('ssl://' . apnsHost . ':' . apnsPort, $error, $errorString, $connectTimeout, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $streamContext);
$numDevices = 0;
$numRequestsSent = 0;
$result = mysql_query($statement);
while ($row = mysql_fetch_assoc($result)) {
$numDevices++;
try {
$deviceToken = $row['device_token'];
//$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', $deviceToken) . chr(0) . chr(strlen($payload)) . $payload;
$apnsMessage = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload; //from http://stackoverflow.com/questions/1642411/sending-multiple-iphone-notifications
$fwriteRes = fwrite($apns, $apnsMessage, strlen($apnsMessage));
echo "Push sent to " . $deviceToken . "<br />\n";
$numRequestsSent++;
}
catch(Exception $e) {
echo "1. Exception: " . $e->getMessage() . "<br />\n";
}
}
fclose($apns);
if ($error != 0 || (isset($errorString) && strlen($errorString) > 0 )) {
echo "ERROR: " . $error . " - ". $errorString . "<br />\n";
}
return $numDevices . " iOS devices. " . $numRequestsSent . " requests sent.";
}