[英]phonegap-plugin-push not working with iOS 9
I am using the new plugin " phonegap-plugin-push " which override the old PushPlugin for push notification with cordova Apps. 我正在使用新的插件“ phonegap-plugin-push ”,该插件使用cordova Apps覆盖了旧的PushPlugin进行推送通知。
The notifications are working perfectly on both android and iOS 8 but when I use iOS 9 it registered successfully and return the token and the back-end code return success but the device doesn't receive the notification! 通知在android和iOS 8上都可以正常运行,但是当我使用iOS 9时,它成功注册并返回令牌,后端代码返回成功,但设备未收到通知!
here is front-end 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
});
and here is my back-end 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);
}
Any help with that please?! 有什么帮助吗? Thanks in advance
提前致谢
I found the solution of my problem, 我找到了解决问题的办法,
You can find detailed answer in this article 您可以在本文中找到详细的答案
Actually it's not certain thing but it's combination of more than one factor 1- be sure to use Xcode 7.1.1 (latest stable version till now) 2- be sure to create APNS Production NOT DEVELOPMENT certificate then download it 实际上这不是确定的事情,但是它是一个以上因素的组合1-确保使用Xcode 7.1.1(到目前为止最新的稳定版本)2-确保创建APNS Production NOT DEVELOPMENT证书然后下载
3- drag it or open it with keychain access expand it and export the private key as yourAppNameKey.p12 3-拖动它或通过钥匙串访问将其打开以展开它,并将私钥导出为yourAppNameKey.p12
4- then we need to generate the pem file for the certificate,So via terminal write : 4-然后我们需要为证书生成pem文件,因此通过终端写入:
openssl x509 -in aps_production.cer -inform der -out yourAppNameCert.pem
Note : ins the last step we used the certificate which we downloaded in step 2 注意:在最后一步中,我们使用了在步骤2中下载的证书
5- now we will Convert the private key's .p12 file into a .pem file: 5-现在,我们将私钥的.p12文件转换为.pem文件:
openssl pkcs12 -nocerts -out yourAppNameKey.pem -in yourAppNameKey.p12
Note : you will be asked to enter the password you used to export the private key and insert a pass phrase and confirm it to use in the server side code 注意:将要求您输入用于导出私钥的密码,并插入一个密码短语,并确认该密码可在服务器端代码中使用
6 - Finally we will combine the certificate and key into a single .pem file: 6-最后,我们将证书和密钥合并到一个.pem文件中:
cat PushChatCert.pem PushChatKey.pem > ck.pem
here is a sample of the server side code 这是服务器端代码的示例
Hope it works with everyone .. Thanks 希望它与大家一起工作..谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.