From f8bbee2634329595711d33ae82923f23a3ddb7fc Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 6 Oct 2016 13:20:23 -0400 Subject: store notification last update in db --- examples/lib/okpush/apn.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'examples/lib/okpush/apn.js') diff --git a/examples/lib/okpush/apn.js b/examples/lib/okpush/apn.js index 5e13e15..b6909f6 100644 --- a/examples/lib/okpush/apn.js +++ b/examples/lib/okpush/apn.js @@ -9,17 +9,21 @@ function init (config) { apnProvider = new apn.Provider(config.apn.connection) } -function push (tokens, note) { - tokens.forEach(function(token){ - connection.send(note, token).then( function (response) { - response.sent.forEach( function (token) { - // notificationSent(user, token) - }) +function push (note) { + db.getAllDevices(function(err, tokens){ + if (err) { + console.error("Error fetching devices:", err) + return + } + connection.send(note, tokens).then( function (response) { + // response.sent.forEach( function (token) { + // notificationSent(user, token) + // }) response.failed.forEach( function (failure) { if (failure.error) { // A transport-level error occurred (e.g. network problem) // notificationError(user, token, failure.error); - } else { + } else if (failure.status == 410) { // `failure.status` is the HTTP status code // `failure.response` is the JSON payload // notificationFailed(token, failure.status, failure.response); -- cgit v1.2.3-70-g09d2