无法通过Ionic和Cordova接收推送通知

时间:2016-03-26 00:00:30

标签: cordova ionic-framework apple-push-notifications phonegap-plugins

我试图通过Ionic和Cordova接收推送通知,但我无法找到错误发生的位置,因为一切似乎都在顺利进行。

首先,为了调试,我正在开始一个新的,干净的离子项目。这些是我的确切命令:

ionic start myApp tabs
cd myApp
ionic platform add ios
cordova plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX"

然后我将其添加到$ionicPlatform.ready(function(){...})块:

var push = PushNotification.init({
    ios: {
        alert: "true",
        badge: "true",
        sound: "true"
    }
  });

push.on('registration', function(data) {
  console.log(data);
});

push.on('notification', function(data) {
  console.log(data);
});

push.on('error', function(e) {
  console.log(e);
});

将其记录到Xcode控制台:

Push Plugin register success: <xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx>
2016-03-26 00:51:49.286 HelloCordova[913:278481] {"registrationId":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}

但是,当我尝试在Node.js中使用apn发送通知时,即使Node中没有发生错误,也不会收到它们。我也无法通过Mac应用程序商店中的APN Tester接收通知,即使一切似乎都运行正常。

当我按照phonegap-plugin-push文档的建议测试我的key.pem和cert.pem文件时,我明白了:

openssl s_client -connect gateway.push.apple.com:2195 -cert cert.pem -key key.pem
CONNECTED(00000003)
depth=1 /C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
 0 s:/C=US/ST=California/L=Cupertino/O=Apple Inc./CN=gateway.push.apple.com
   i:/C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
 1 s:/C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
   i:/O=Entrust.net/OU=www.entrust.net/CPS_2048 incorp. by ref. (limits liab.)/OU=(c) 1999 Entrust.net Limited/CN=Entrust.net Certification Authority (2048)
---
Server certificate
-----BEGIN CERTIFICATE-----
**VERY LONG CERTIFICATE**
-----END CERTIFICATE-----
subject=/C=US/ST=California/L=Cupertino/O=Apple Inc./CN=gateway.push.apple.com
issuer=/C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
---
Acceptable client certificate CA names
/C=US/O=Apple Inc./OU=Apple Certification Authority/CN=Apple Root CA
/C=US/O=Apple Inc./OU=Apple Worldwide Developer Relations/CN=Apple Worldwide Developer Relations Certification Authority
/C=US/O=Apple Inc./OU=Apple Certification Authority/CN=Apple Application Integration Certification Authority
---
SSL handshake has read 3144 bytes and written 2148 bytes
---
New, TLSv1/SSLv3, Cipher is AES256-SHA
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1
    Cipher    : AES256-SHA
    Session-ID: 
    Session-ID-ctx: 
    Master-Key: **MY-MASTER-KEY**
    Key-Arg   : None
    Start Time: 1458949317
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)
---
closed

对于为何没有给出预期结果的任何建议将不胜感激。

0 个答案:

没有答案