Last active
August 29, 2015 14:15
-
-
Save yodarjun/4d638d3003a164efc68e 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
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