ios - phonegap-plugin-push 不适用于 iOS 9
<p><p>我正在使用新插件“<a href="https://github.com/phonegap/phonegap-plugin-push" rel="noreferrer noopener nofollow">phonegap-plugin-push</a>”,它会覆盖旧的 <a href="https://github.com/phonegap-build/PushPlugin" rel="noreferrer noopener nofollow">PushPlugin</a>,以便通过 cordova 应用程序进行推送通知。</p>
<p>通知在 android 和 iOS 8 上都可以正常工作,但是当我使用 iOS 9 时,它注册成功并返回 token ,后端代码返回成功,但设备没有收到通知!</p>
<p>这里是前端代码</p>
<pre><code>var push = PushNotification.init({ "android": {"senderID": "12345679"},
"ios": {"alert": "true", "badge": "true", "sound": "true"}, "windows": {} } );
push.on('registration', function(data) {
var token = data.registrationId
});
push.on('notification', function(data) {
// data.message,
// data.title,
// data.count,
// data.sound,
// data.image,
var data =data.additionalData
});
push.on('error', function(e) {
// e.message
});
</code></pre>
<p>这是我的后端代码</p>
<pre><code>$deviceToken = "019451814eff224c5dceca49b34b7b635d0716c21da2a77e7fd0809fd508d6z4";
$passphrase = 'myPassPhrase';
$message = 'You have recieved new notification!';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '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',
'data' => 'test data'
);
// 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);
}
</code></pre>
<p>请问有什么帮助吗?!
提前致谢</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我找到了解决问题的方法,</p>
<p>你可以在这个<a href="http://w34.co/tutorials/creating-pem-file-for-ios-push-notifications/" rel="noreferrer noopener nofollow">article</a>找到详细的答案</p>
<p>实际上这不是确定的事情,而是多个因素的组合
1-一定要使用Xcode 7.1.1(目前最新的稳定版本)
2- 一定要创建 APNS Production NOT DEVELOPMENT 证书然后下载它</p>
<p> <a href="/image/cl8sJ.png" rel="noreferrer noopener nofollow"><img src="/image/cl8sJ.png" alt="enter image description here"/></a> </p>
<p>3- 拖动它或使用钥匙串(keychain)访问打开它展开它并将私钥导出为 yourAppNameKey.p12 </p>
<p> <a href="/image/EH0Jp.png" rel="noreferrer noopener nofollow"><img src="/image/EH0Jp.png" alt="enter image description here"/></a> </p>
<p>4-然后我们需要为证书生成pem文件,所以通过终端写入:</p>
<pre><code> openssl x509 -in aps_production.cer -inform der -out yourAppNameCert.pem
</code></pre>
<p>注意:在最后一步中,我们使用了在步骤 2 中下载的证书</p>
<p>5- 现在我们将私钥的 .p12 文件转换为 .pem 文件:</p>
<pre><code>openssl pkcs12 -nocerts -out yourAppNameKey.pem -in yourAppNameKey.p12
</code></pre>
<p>注意:您将被要求输入用于导出私钥的密码并插入密码短语并确认它以在服务器端代码中使用</p>
<p>6 - 最后,我们将证书和 key 合并到一个 .pem 文件中:</p>
<pre><code>cat PushChatCert.pem PushChatKey.pem > ck.pem
</code></pre>
<p> <a href="https://drive.google.com/file/d/0B0zVybqvfI8dY0JwYW1mWENEcWc/view?usp=sharing" rel="noreferrer noopener nofollow">here is a sample of the server side code</a> </p>
<p>希望它适用于每个人......谢谢</p></p>
<p style="font-size: 20px;">关于ios - phonegap-plugin-push 不适用于 iOS 9,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/33730605/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/33730605/
</a>
</p>
页:
[1]