某些用户不再收到或发送IOS推送通知

时间:2016-02-29 09:14:48

标签: php ios iphone notifications push-notification

我遇到了以下问题。

我有一个IOS应用程序,它运行了两年,推送通知没有问题。

我基本上做的是将所有注册ID存储在数据库中,并通过php脚本向他们发送通知:

// Open a connection to the APNS server
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

$title = "My App";

$nachricht = $message['teams']['heim']." - ". $message['teams']['aus'];
// Create the payload body
$body['aps'] = array(
    'alert' => $title. " \n " . $nachricht,
    'sound' => 'default',
    'message' => $nachricht
    );
$body['id'] = $message['spiel'];
$body['message'] = $nachricht;
$body['title'] = $title;

// Encode the payload as JSON
$payload = json_encode($body);

for ($i = 0; $i < count($registation_ids); $i++) {
    // Build the binary notification
    $msg = chr(0) . pack('n', 32) . pack('H*', $registation_ids[$i]) . pack('n', strlen($payload)) . $payload;

    // Send it to the server
    $result = fwrite($fp, $msg, strlen($msg));

}
fclose($fp);

我从未对此脚本有任何问题,但现在几周前收到通知的一些用户不再收到它们了。首先,我认为我的证书和提供的配置文件出了问题,但具有相同IOS版本和App版本的其他用户仍然收到通知。 我还检查了用户不再接收消息的通知设置,它们是正确的。

什么可能导致这个问题? 目前我不知道这个错误发生在哪里。

1 个答案:

答案 0 :(得分:1)

function send_notification_ios($registatoin_ids,$message) {

        $ctx = stream_context_create();
        stream_context_set_option($ctx, 'ssl', 'passphrase', '');
        //for sandbox url

        stream_context_set_option($ctx, 'ssl', 'local_cert', 'pemios/dev_apns_vookar.pem');
        $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);

        //for live url

        // stream_context_set_option($ctx, 'ssl', 'local_cert', 'pemios/apns-production.pem');
        //$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);

        stream_set_blocking ($fp, 1);
        if (!$fp) {
            echo "Failed to connect (stream_socket_client): $err $errstr";
        }
        else {
            $apple_expiry = time() + (90 * 24 * 60 * 60);
            foreach($registatoin_ids  as $key=>$value){
                $apple_identifier = $key;
                $deviceToken = $value;
                $payload = json_encode($message);
                $msg = pack("C", 1) . pack("N", $apple_identifier) . pack("N", $apple_expiry) . pack("n", 32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n", strlen($payload)) . $payload;
                fwrite($fp, $msg);
                //checkAppleErrorResponse($fp);
            }
        }
        usleep(500000);
        //checkAppleErrorResponse($fp);
        //mysql_close($con);
        fclose($fp);
        return true;
    }



 $iphonedeviceId = array($requestDataIos[0]['device_id']);
                    $body = array();

                      $body['aps']['alert'] = $message;
                    $body['aps']['userId'] = $params['user_id'];
                    $body['aps']['request_id'] = $params['request_id'];
                    $body['aps']['vendor_id'] = $params['vendor_id'];
                   // $body['aps']['request_vendor_arrived'] = 1;
                    $body['aps']['sender'] = $userDetails[0]['full_name'];


                    $body['aps']['badge'] = +1;
                    $body['aps']['userId'] = $userId;
                    $body['aps']['sound'] = "default";
                    $body['aps']['content-available'] = "1";
                    $body['aps']['nt'] = "3";
                    $this->send_notification_ios($iphonedeviceId, $body);