Skip to content

Instantly share code, notes, and snippets.

@yodarjun
Last active August 29, 2015 14:15
Show Gist options
  • Save yodarjun/4d638d3003a164efc68e to your computer and use it in GitHub Desktop.
Save yodarjun/4d638d3003a164efc68e to your computer and use it in GitHub Desktop.
angular
.module('ngPushWoosh', [])
.factory('PushWoosh', function($q, $state) {
'use strict';
var PW_APP_ID = <YOUR PUSHWOOSH APP ID>;
var pushNotification;
function initPW(pushwooshAppId) {
pushwooshAppId = PW_APP_ID;
pushNotification = window.plugins.pushNotification;
// Initialize the plugin
pushNotification.onDeviceReady({ pw_appid: pushwooshAppId });
//reset badges on app start
pushNotification.setApplicationIconBadgeNumber(0);
}
var pw = {
init: function(pushwooshAppId) {
if (window.ionic.Platform.isIOS()) {
initPW(pushwooshAppId);
} else {
console.warn('[ngPushWoosh] Unsupported platform');
}
},
registerDevice: function() {
var deferred = $q.defer();
if (window.ionic.Platform.isIOS()) {
pushNotification.registerDevice(deferred.resolve, deferred.reject);
} else {
console.warn('[ngPushWoosh] Unsupported platform');
deferred.resolve(false);
}
return deferred.promise;
},
unregisterDevice: function() {
var deferred = $q.defer();
pushNotification.unregisterDevice(deferred.resolve, deferred.reject);
return deferred.promise;
}
};
return pw;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment