php - 推送通知角标(Badge)计数未在 iOS 上更新

标签 php ios push-notification apple-push-notifications

推送通知角标(Badge)计数没有增加。它始终显示 1。我使用 php 从服务器发送推送,代码如下:

    $apnsHost = 'gateway.sandbox.push.apple.com';
    $apnsCert = 'project_dev.pem';

    $apnsPort = 2195;
    $badgecount=1;

    $streamContext = stream_context_create();

    stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
if (!$apns){
    exit("Failed to connect: $error $errorString" . PHP_EOL);
}else{
    $messageHeader = (strlen($message) > 26) ? substr($message,0,26).'...' : $message;

$msgd=explode(':',$message);

$payload['aps'] = array('alert' => $messageHeader,'badge' => $badgecount, 'sound' => 'default','mess'=>$fromUserId.'||'.$userNamee.'||'.$userimage.'||'.$message,'type'=>'reply', 'unread_count'=>$unread_count);

$output = json_encode($payload);
$token = pack('H*', str_replace(' ', '', $token));

$apnsMessage = chr(0) . chr(0) . chr(32) . $token . chr(0) . chr(strlen($output)) .     $output;

fwrite($apns, $apnsMessage);

fclose($apns);
}

最佳答案

badgecount 总是由服务器端发送。看起来你发送的是 $badgecount=1;总是。用其他值更新它然后检查。它肯定反射(reflect)在 IOS 上。

关于php - 推送通知角标(Badge)计数未在 iOS 上更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34082709/

相关文章:

php - 如何并行读取多个文件?

ios - 如何使用 RxSwift 和 RxSwiftDataSources 将 TableView 与代表不同数据类型的多个部分绑定(bind)?

ios - 在 xcode 9.1 中创建 .mm 文件

javascript - Chrome 上的 Firebase 云消息传递未经授权错误 401

Android GCM 不向设备发送通知消息

php - Joomla 版本历史记录错误 - UCM_History 表

php - 可以从外部读取 PHP 文件吗?

php - 声明函数时 'static'是什么意思

ios - 如何在 ios 中使用 View 高度动态调整阴影?

php - IOS 推送失败,错误消息为 : fwrite(): send of 474 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host