Skip to content

Instantly share code, notes, and snippets.

@panaggio
Created March 25, 2016 22:13
Show Gist options
  • Save panaggio/ae70d5ef12b759812007 to your computer and use it in GitHub Desktop.
Save panaggio/ae70d5ef12b759812007 to your computer and use it in GitHub Desktop.
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