Skip to content

Instantly share code, notes, and snippets.

@mulhoon
Created February 11, 2016 15:31
Show Gist options
  • Save mulhoon/61a9a7c7cf6dae5aef26 to your computer and use it in GitHub Desktop.
Save mulhoon/61a9a7c7cf6dae5aef26 to your computer and use it in GitHub Desktop.
JS for One Signal
App.push = (function(){
var id = '[---App ID---]';
var notificationOpenedCallback = function(jsonData) {
console.log('didReceiveRemoteNotificationCallBack: ' + JSON.stringify(jsonData));
};
var init = function(customid, callback){
id = customid ? customid : id;
console.log('Initializing push');
if(!window.cordova){
return;
}
window.plugins.OneSignal.init(id, {googleProjectNumber: ""}, notificationOpenedCallback);
// Show an alert box if a notification comes in when the user is in your app.
window.plugins.OneSignal.enableInAppAlertNotification(true);
getID(callback);
};
var getID = function(callback){
console.log('Get push ids');
window.plugins.OneSignal.getIds(function(ids) {
console.log('getIds: ' + JSON.stringify(ids));
if(callback){
callback();
}
});
};
return {
init:init
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment