Created
March 25, 2016 22:13
-
-
Save panaggio/ae70d5ef12b759812007 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.push = (function() { | |
var instance; | |
var config = { | |
ios: { | |
alert: true, | |
badge: true, | |
sound: true, | |
categories: { | |
a: { | |
yes: { | |
title: 'Approve', | |
callback: 'App.push.approve', | |
foreground: false, | |
destructive: false, | |
}, | |
}, | |
ar: { | |
yes: { | |
title: 'Approve', | |
callback: 'App.push.approve', | |
foreground: false, | |
destructive: false, | |
}, | |
no: { | |
title: 'Reject', | |
callback: 'App.push.reject', | |
foreground: false, | |
destructive: true, | |
}, | |
}, | |
}, | |
}, | |
}; | |
var buildCallback = function(msg) { | |
return function() { | |
console.log( | |
'[App.push] ' + msg + ': ' + | |
JSON.stringify(arguments) | |
); | |
}; | |
}; | |
var pushModule = { | |
init: function() { | |
instance = PushNotification.init(config); | |
instance.on('registration', function(data) { | |
buildCallback('registration')(data); | |
App.device.save({ | |
token: data.registrationId, | |
}).then( | |
buildCallback('registration success'), | |
buildCallback('registration error') | |
); | |
}); | |
instance.on('notification', function(data) { | |
buildCallback('notification')(data); | |
instance.finish(buildCallback('notification finished')); | |
}); | |
instance.on('error', function() { | |
buildCallback('notification')(arguments); | |
}); | |
}, | |
approve: function(data) { | |
buildCallback('approve')(data); | |
instance.finish( | |
buildCallback('approve finished'), | |
buildCallback('approve error'), | |
data.additionalData.notId | |
); | |
}, | |
reject: function(data) { | |
buildCallback('approve')(data); | |
instance.finish( | |
buildCallback('approve finished'), | |
buildCallback('approve error'), | |
data.additionalData.notId | |
); | |
}, | |
}; | |
return pushModule; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment