Apple Push notifications. Trying something else

This commit is contained in:
Martin Donnelly 2016-04-29 11:04:14 +01:00
parent 2a3ed8acb2
commit b66a9f3650
2 changed files with 34 additions and 18 deletions

42
app.js
View File

@ -35,15 +35,37 @@ var isProduction = false;
var iosTokens = [];
var apnTimer = 0;
var apns = require("apns"), options, connection, notification;
var apn = require('apn');
var apnService = new apn.connection({ production: false });
apnService.on('connected', function() {
logger.debug('APN Connected');
});
apnService.on('transmitted', function(notification, device) {
logger.debug('APN Notification transmitted to:' + device.token.toString('hex'));
});
apnService.on('transmissionError', function(errCode, notification, device) {
logger.error('APNNotification caused error: ' + errCode + ' for device ', device, notification);
if (errCode === 8) {
logger.error('A error code of 8 indicates that the device token is invalid. This could be for a number of reasons - are you using the correct environment? i.e. Production vs. Sandbox');
}
});
apnService.on('timeout', function() {
logger.debug('Connection Timeout');
});
apnService.on('disconnected', function() {
logger.debug('Disconnected from APNS');
});
apnService.on('socketError', logger.error);
options = {
keyFile : "conf/key.pem",
certFile : "conf/cert.pem",
debug : true
};
connection = new apns.Connection(options);
@ -255,13 +277,7 @@ app.post('/api/v1/register/ios', function(req, res) {
apnConnection.pushNotification(note, myDevice);*/
logger.warn('Sending Apple Notifications');
notification = new apns.Notification();
notification.device = new apns.Device(iosTokens[0]);
notification.alert = "Hello World !";
connection.sendNotification(notification);
}, 30000);

View File

@ -17,10 +17,10 @@
"method-override": "*",
"minibus": "^3.1.0",
"morgan": "*",
"mqtt": "^1.7.0",
"mqtt": "^1.10.0",
"mqtt_over_websockets": "0.0.1",
"node-localstorage": "^1.1.2",
"request": "*",
"request": "^2.72.0",
"websocket": "^1.0.22"
},
"devDependencies": {
@ -37,7 +37,7 @@
"gulp-autoprefixer": "^3.1.0",
"gulp-cache": "^0.4.2",
"gulp-concat": "^2.6.0",
"gulp-cssnano": "^2.1.1",
"gulp-cssnano": "^2.1.2",
"gulp-debug": "^2.1.2",
"gulp-google-webfonts": "0.0.12",
"gulp-html-replace": "^1.5.5",
@ -49,14 +49,14 @@
"gulp-notify": "^2.2.0",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^1.5.3",
"jshint": "^2.9.1",
"jshint": "^2.9.2",
"jsonfile": "^2.3.0",
"log4js": "^0.6.35",
"mocha": "^2.4.5",
"mqtt-ws": "^0.2.0",
"node-cron": "^1.1.1",
"require-dir": "^0.3.0",
"should": "^8.2.2",
"should": "^8.3.1",
"string": "^3.3.1",
"sugar-date": "^1.5.1",
"superagent": "^1.7.2",