使用php的IOS推送通知

I have create pushnotification for ios. Following coding i got from website. And the device token is from Our Apple device that i have changed.

<?php
$deviceToken = '0f744707bebcf74f9b7c25d48e3358945fxxx01da5ddb387462c7eaf61bbad78';
$msg_push="hi there";
$deviceToken = str_replace(" ", "", $deviceToken);
// Put your private key's passphrase here:
$passphrase = 'pushchat';
// Put your alert message here:
$message = $msg_push;
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert.pem');//'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
    'ssl://gateway.sandbox.push.apple.com:2195', $err,
    $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
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,
    'sound' => 'default'
    );
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$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);
?>

The pushcert.pem file i have included in the same folder. Know when i run this page in server i get the msg"Connected to APNS Message successfully delivered". But i don't get the notification message in my apple device. So is any error in this code. What is wrong here?

duanjuelu8874
duanjuelu8874 不,这个编码很好,你在appdelegate中为推送通知添加了什么
大约 5 年之前 回复
duangou1551
duangou1551 我从raywenderlich.com/32960/...这边得到了它
大约 5 年之前 回复
dongluolie3487
dongluolie3487 显示远程通知详细信息
大约 5 年之前 回复
dsfliu1129
dsfliu1129 你是否从应用程序端实现了代码..?如果是,则检查他们是否使用了正确的证书和正确的配置文件。
大约 5 年之前 回复

1个回答



可能是因为您的应用处于生产环境中,因此您必须从'ssl://gateway.sandbox中删除沙箱。 push.apple.com:2195'

或</ p>

这可能是因为在特定包标识符的apple帐户中未启用推送通知。 它也可能是因为推送通知的方法没有在应用程序中定义。</ p>
</ div>

展开原文

原文

It can be because your app is in production environment then you have to remove the sandbox from the 'ssl://gateway.sandbox.push.apple.com:2195'

or

It may be because push notifications are not enabled in the apple account for the particular bundle identifier.It can also be because methods for push notification are not defined in the app.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐