// // PushNotification.js // // Created by Olivier Louvignes on 06/05/12. // Inspired by Urban Airship Inc orphaned PushNotification phonegap plugin. // // Copyright 2012 Olivier Louvignes. All rights reserved. // MIT Licensed (function(cordova) { function PushNotification() {} // Call this to register for push notifications and retreive a deviceToken PushNotification.prototype.registerDevice = function(config, callback) { cordova.exec(callback, callback, "PushNotification", "registerDevice", config ? [config] : []); }; // Call this to retreive pending notification received while the application is in background or at launch PushNotification.prototype.getPendingNotifications = function(callback) { cordova.exec(callback, callback, "PushNotification", "getPendingNotifications", []); }; // Call this to get a detailed status of remoteNotifications PushNotification.prototype.getRemoteNotificationStatus = function(callback) { cordova.exec(callback, callback, "PushNotification", "getRemoteNotificationStatus", []); }; // Call this to set the application icon badge PushNotification.prototype.setApplicationIconBadgeNumber = function(badge, callback) { cordova.exec(callback, callback, "PushNotification", "setApplicationIconBadgeNumber", [{badge: badge}]); }; // Call this to clear all notifications from the notification center PushNotification.prototype.cancelAllLocalNotifications = function(callback) { cordova.exec(callback, callback, "PushNotification", "cancelAllLocalNotifications", []); }; // Call this to retreive the original device unique id // @warning As of today, usage is deprecated and requires explicit consent from the user PushNotification.prototype.getDeviceUniqueIdentifier = function(callback) { cordova.exec(callback, callback, "PushNotification", "getDeviceUniqueIdentifier", []); }; // Event spawned when a notification is received while the application is active PushNotification.prototype.notificationCallback = function(notification) { var ev = document.createEvent('HTMLEvents'); ev.notification = notification; ev.initEvent('push-notification', true, true, arguments); document.dispatchEvent(ev); }; cordova.addConstructor(function() { if(!window.plugins) window.plugins = {}; window.plugins.pushNotification = new PushNotification(); }); })(window.cordova || window.Cordova || window.PhoneGap);