mirror of
https://gitlab.silvrtree.co.uk/martind2000/SODashServer.git
synced 2025-01-25 16:26:18 +00:00
Apple Push notifications. Trying something else
This commit is contained in:
parent
0fff03846d
commit
2a3ed8acb2
47
app.js
47
app.js
@ -35,33 +35,16 @@ var isProduction = false;
|
||||
var iosTokens = [];
|
||||
var apnTimer = 0;
|
||||
|
||||
var apns = require("apns"), options, connection, notification;
|
||||
|
||||
var settings = {
|
||||
gcm: {
|
||||
id: null, // PUT YOUR GCM SERVER API KEY,
|
||||
options: {},
|
||||
msgcnt: 1,
|
||||
dataDefaults: {
|
||||
delayWhileIdle: false,
|
||||
timeToLive: 4 * 7 * 24 * 3600, // 4 weeks
|
||||
retries: 4
|
||||
}
|
||||
},
|
||||
apn: {
|
||||
gateway: 'gateway.sandbox.push.apple.com',
|
||||
badge: 1,
|
||||
defaultData: {
|
||||
expiry: 5, // 4 weeks
|
||||
sound: 'ping.aiff'
|
||||
}
|
||||
},
|
||||
adm: {
|
||||
client_id: null, // PUT YOUR ADM CLIENT ID,
|
||||
client_secret: null, // PUT YOUR ADM CLIENT SECRET,
|
||||
expiresAfter: 4 * 7 * 24 * 3600, // 4 weeks
|
||||
}
|
||||
options = {
|
||||
keyFile : "conf/key.pem",
|
||||
certFile : "conf/cert.pem",
|
||||
debug : true
|
||||
};
|
||||
var push = require('node-pushnotifications')(settings);
|
||||
|
||||
connection = new apns.Connection(options);
|
||||
|
||||
|
||||
|
||||
mqttConnect.setEmitter(busEmitter);
|
||||
@ -75,10 +58,6 @@ if (process.env.NODE_ENV === 'production') {
|
||||
|
||||
logger.debug('isProduction:', isProduction);
|
||||
|
||||
var options = { };
|
||||
|
||||
var apnConnection = new apn.Connection(options);
|
||||
|
||||
var app = express();
|
||||
|
||||
app.set('port', process.env.PORT || 4545);
|
||||
@ -277,10 +256,12 @@ app.post('/api/v1/register/ios', function(req, res) {
|
||||
apnConnection.pushNotification(note, myDevice);*/
|
||||
|
||||
logger.warn('Sending Apple Notifications');
|
||||
var data = {title: 'New push notification' , message: 'Powered by Martin', otherfields: 'optionally add more data'};
|
||||
push.sendPush(iosTokens, data, function(result) {
|
||||
logger.debug(result);
|
||||
});
|
||||
|
||||
notification = new apns.Notification();
|
||||
notification.device = new apns.Device(iosTokens[0]);
|
||||
notification.alert = "Hello World !";
|
||||
|
||||
connection.sendNotification(notification);
|
||||
|
||||
|
||||
}, 30000);
|
||||
|
@ -26,6 +26,7 @@
|
||||
"devDependencies": {
|
||||
"after": "^0.8.1",
|
||||
"apn": "^1.7.5",
|
||||
"apns": "^0.1.0",
|
||||
"basic-authentication": "^1.6.2",
|
||||
"chai": "^3.5.0",
|
||||
"cheerio": "^0.20.0",
|
||||
@ -54,7 +55,6 @@
|
||||
"mocha": "^2.4.5",
|
||||
"mqtt-ws": "^0.2.0",
|
||||
"node-cron": "^1.1.1",
|
||||
"node-pushnotifications": "^0.1.4",
|
||||
"require-dir": "^0.3.0",
|
||||
"should": "^8.2.2",
|
||||
"string": "^3.3.1",
|
||||
|
Loading…
Reference in New Issue
Block a user