gpt4 book ai didi

ios - 推送通知丢失消息

转载 作者:太空宇宙 更新时间:2023-11-04 02:31:27 27 4
gpt4 key购买 nike

我正在关注此网站上的教程:

https://blog.engineyard.com/2013/developing-ios-push-notifications-nodejs

在我的应用程序中传递推送通知。

到目前为止我已经成功创建了证书和其他文件。在服务器端,我无法通过“建立连接”步骤。

我可以在运行应用程序时在控制台中获取我的设备 token 。在教程中据说,建立连接后,终端控制台应该给出“网关已连接”的输出。

但我没有收到此消息。最糟糕的情况是我也没有收到任何错误消息。我想知道出了什么问题。尽管我在首先建立连接时遇到了一些错误,例如凭据不足、mac 验证错误,但我解决了这些问题。现在既没有收到任何错误,也没有收到正确的消息。

我还在此处添加了我的终端控制台

SIVAs-MacBook-Air:~ AAA$ cd Desktop/
SIVAs-MacBook-Air:Desktop AAA$ cd poservices/
SIVAs-MacBook-Air:poservices AAA$ node agent/_header.js
SIVAs-MacBook-Air:poservices AAA$ node agent/_header.js
SIVAs-MacBook-Air:poservices AAA$`


var join = require('path').join
, pfx = join(__dirname, '../_certs/pfx.p12');

/*!
* Create a new gateway agent
*/

var apnagent = require('apnagent')
, agent = module.exports = new apnagent.Agent();


/*!
* Configure agent
*/

agent
.set('pfx file', pfx)
.enable('sandbox');

/*!
* Error Mitigation
*/

agent.on('message:error', function (err, msg) {
connect.log('error1');
switch (err.name) {

// This error occurs when Apple reports an issue parsing the message.
case 'GatewayNotificationError':
console.log('[message:error] GatewayNotificationError: %s', err.message);


// The err.code is the number that Apple reports.
// Example: 8 means the token supplied is invalid or not subscribed
// to notifications for your application.
if (err.code === 8) {
console.log(' > %s', msg.device().toString());
// In production you should flag this token as invalid and not
// send any futher messages to it until you confirm validity
}

break;

// This happens when apnagent has a problem encoding the message for transfer
case 'SerializationError':
console.log('[message:error] SerializationError: %s', err.message);

break;

// unlikely, but could occur if trying to send over a dead socket
default:
console.log('[message:error] other error: %s', err.message);
break;
}
});

/*!
* Make the connection
*/


agent.connect(function (err) {
// gracefully handle auth problems
if (err && err.name === 'GatewayAuthorizationError') {

console.log('Authentication Error: %s', err.message);
process.exit(1);
}

// handle any other err (not likely)
else if (err) {
console.log('error1');
throw err;
}

// it worked!
var env = agent.enabled('sandbox')
? 'sandbox'
: 'production';
console.log('apnagent [%s] gateway connected', env);
});

最佳答案

您需要添加

agent.set('passphrase', '<YOUR_PASSWORD>');

之后

agent.set('pfx file', pfx).enable('sandbox');

关于ios - 推送通知丢失消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26366077/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com