关于apn提供者的APNSwork,但不是通过nodeJS - 生产

时间:2018-01-18 05:19:11

标签: javascript ios node.js apple-push-notifications

我设置了一个nodeJS脚本来发送APN。在开发过程中它始终有效,但是当我开始生产时,它们永远无法通过。我尝试使用相同的通知ID,它在Easy Apn提供程序中使用我的生产证书发送和发送内容,并且它会通过。我不知道为什么我会失败。如果我的个人资料或证书不对,那么简单的apn就不会通过?

Easy apn successfully sent

apn config

var options = {
    token: {
    cert: "certificate.pem",
    pfx: "Certificate.p12",
    key: "AuthKey_XCVK62CSQF.p8",
    keyId: "3Z6SEF7GE5",
    teamId: "ASQJ3L7765"
    },
    production: true,
     gateway: 'gateway.push.apple.com',      // gateway address
     port: 2195
   };
var apnProvider = new apn.Provider(options);

结果:

//IOS notif function
function SendIOSNotification(token, message, sound, payload, badge){
var deviceToken = token; //phone notification id
var notification = new apn.Notification(); //prepare notif
notification.topic = 'com.GL.Greek-Life'; // Specify your iOS app's Bundle ID (accessible within the project editor)
notification.expiry = Math.floor(Date.now() / 1000) + 3600; // Set expiration to 1 hour from now (in case device is offline)
notification.badge = badge; //selected badge
notification.sound = sound; //sound is configurable
notification.alert = message; //supports emoticon codes
notification.payload = {id: payload}; // Send any extra payload data with the notification which will be accessible to your app in didReceiveRemoteNotification
    apnProvider.send(notification, deviceToken).then(function(result) {  //send actual notifcation
    // Check the result for any failed devices

    var subToken = token.substring(0, 6);
    console.log("Succesfully sent message to ", subToken);
    }).catch( function (error) {
            console.log("Faled to send message to ", subToken);
    })
}

成功发送消息给5D ..

编辑: 当显示我的响应时,我看到通知实际上失败了403错误(id不存在,但它可以很好地使用简单的apn)。

我认为它是因为我生成了一个非生产ID,但我不明白这是怎么可能的。我签署了我的构建并在testflight上删除它并且我已经删除了所有开发配置文件,并且只有生产配置文件和证书。不确定thiis是怎么发生的

1 个答案:

答案 0 :(得分:0)

问题在于,当我改为制作并且它无法正常工作时,我尝试创建一个新的.p8键。它可能在那时工作,但我只更改了.p8的引用,而不是我的开发人员帐户上找到的.p8键的关键参数。一旦我更新了该密钥,我的所有问题都得到了解决