【发布时间】:2013-07-16 00:02:34
【问题描述】:
我正在开发一个使用推送通知的 iOS 应用程序,我已经实现了该应用程序和服务器端,如果我只发送一两个通知,它就可以很好地工作。当我需要向所有用户发送相同的通知时,问题就出现了,通知只会发送给循环的第一个用户。 我在沙箱中,所以我想知道沙箱环境是否有任何限制,因为我读过APNS服务没有限制。 有什么想法吗?
提前致谢,
更新的解决方案:
我必须检查苹果的响应,我正在向无效令牌发送推送,苹果断开了我与服务器的连接。通过以下功能,我解决了这个问题。 谢谢@Eran 和this post
/* FUNCTION to check if there is an error response from Apple
* Returns TRUE if there was and FALSE if there was not
*/
public function checkAppleErrorResponse($fp) {
//byte1=always 8, byte2=StatusCode, bytes3,4,5,6=identifier(rowID).
// Should return nothing if OK.
//NOTE: Make sure you set stream_set_blocking($fp, 0) or else fread will pause your script and wait
// forever when there is no response to be sent.
$apple_error_response = fread($fp, 6);
if ($apple_error_response) {
// unpack the error response (first byte 'command" should always be 8)
$error_response = unpack('Ccommand/Cstatus_code/Nidentifier', $apple_error_response);
if ($error_response['status_code'] == '0') {
$error_response['status_code'] = '0-No errors encountered';
} else if ($error_response['status_code'] == '1') {
$error_response['status_code'] = '1-Processing error';
} else if ($error_response['status_code'] == '2') {
$error_response['status_code'] = '2-Missing device token';
} else if ($error_response['status_code'] == '3') {
$error_response['status_code'] = '3-Missing topic';
} else if ($error_response['status_code'] == '4') {
$error_response['status_code'] = '4-Missing payload';
} else if ($error_response['status_code'] == '5') {
$error_response['status_code'] = '5-Invalid token size';
} else if ($error_response['status_code'] == '6') {
$error_response['status_code'] = '6-Invalid topic size';
} else if ($error_response['status_code'] == '7') {
$error_response['status_code'] = '7-Invalid payload size';
} else if ($error_response['status_code'] == '8') {
$error_response['status_code'] = '8-Invalid token';
} else if ($error_response['status_code'] == '255') {
$error_response['status_code'] = '255-None (unknown)';
} else {
$error_response['status_code'] = $error_response['status_code'].'-Not listed';
}
echo '<br><b>+ + + + + + ERROR</b> Response Command:<b>' . $error_response['command'] . '</b> Identifier:<b>' . $error_response['identifier'] . '</b> Status:<b>' . $error_response['status_code'] . '</b><br>';
echo 'Identifier is the rowID (index) in the database that caused the problem, and Apple will disconnect you from server. To continue sending Push Notifications, just start at the next rowID after this Identifier.<br>';
return true;
}
return false;
}
【问题讨论】:
-
APN服务有限制,每次只能发送256字节的数据,
-
@kirtiavaiya 是的,我知道,我在发送消息之前检查了它,所以这不是问题。
-
我认为如果您发送格式和大小正确的数据包(有效负载),那么这是与通过循环接收器列表向 APNS 发送数据有关的问题。 .
-
@mrm_arrasate 这是troubleshooting push notifications 的好读物。
-
stream_set_blocking($fp, 0)可能不适用于 tls
标签: ios iphone push-notification apple-push-notifications