Apple Push notifications. Trying something else. again

This commit is contained in:
Martin Donnelly 2016-04-29 14:49:18 +01:00
parent 2a137db33f
commit 9e82a0998f

View File

@ -10,6 +10,9 @@ var util = require('util');
var apn = require('apn');
var jsonfile = require('jsonfile');
var file = 'data/iostokens.json';
var apnService = new apn.connection({ key: 'conf/key.pem',
cert: 'conf/cert.pem', production: false });
@ -68,6 +71,14 @@ var officeController = function(neweventbus) {
}
};
jsonfile.readFile(file, function (err, obj) {
if (err){
logger.error(err);
}
logger.debug(obj);
}.bind(this));
this.saveTimer = 0;
var self = this;
this.schedule = {};
this.todaysList = {};
@ -133,6 +144,11 @@ var officeController = function(neweventbus) {
}.bind(this),60000);
};
officeController.prototype.saveData = function() {
jsonfile.writeFileSync(file, this.iosTokens);
};
officeController.prototype.sendiOSAPN = function(packet) {
logger.info('Sending the same notification each of the devices with one call to pushNotification.');
var note = new apn.notification();
@ -346,6 +362,8 @@ officeController.prototype.registeriOSToken = function(id) {
if (this.iosTokens.indexOf(id) === -1) {
this.iosTokens.push(id);
logger.info('C - IOS Device registered.');
clearTimeout(this.saveTimer);
this.saveTimer = setTimeout(function(){this.saveData();}.bind(this), 10000);
}
};