私はこのウェブサイトのチュートリアルに従っています:
https://blog.engineyard.com/2013/developing-ios-push-notifications-nodejs
アプリでプッシュ通知を配信します。
これまでのところ、証明書とその他のファイルを正常に作成しました。サーバー側では、Making the Connection ステップを通過できませんでした。
アプリの実行中にコンソールでデバイス トークンを取得できます。チュートリアルでは、接続を確立した後、ターミナル コンソールに「ゲートウェイが接続されました」という出力が表示されるはずです。
しかし、私はこのメッセージを受け取っていません。最悪の場合、エラー メッセージも表示されません。何がうまくいかなかったのだろうか。最初に接続を確立する際に、認証情報が不十分である、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);
});