From e64b5e3a766882ec89ff2305607550ba7b1dfdb7 Mon Sep 17 00:00:00 2001 From: Harri Sarsa Date: Mon, 2 Sep 2013 14:14:06 +0300 Subject: [PATCH] PushNotification JavaScript file --- PushNotification/README.md | 14 +++++ PushNotification/www/PushNotification.js | 65 ++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 PushNotification/README.md create mode 100644 PushNotification/www/PushNotification.js diff --git a/PushNotification/README.md b/PushNotification/README.md new file mode 100644 index 0000000..829a798 --- /dev/null +++ b/PushNotification/README.md @@ -0,0 +1,14 @@ +# Push plugin + +Forked from https://github.com/phonegap-build/PushPlugin – see repo README for usage instructions. + +Adapted for Steroids by AppGyver, Inc. + +##Configuration in Steroids + +The Push plugin is bundled in with AppGyver Scanner for iOS, so there's no need to install it separately. Simply copy the JavaScript file in the `www` directory to your project and load them in your app, e.g. with a `" tag. + +You also need to make sure that your `config.ios.xml` file has the correct plugin tag defined: + +* config.ios.xml: + `` diff --git a/PushNotification/www/PushNotification.js b/PushNotification/www/PushNotification.js new file mode 100644 index 0000000..acfef1f --- /dev/null +++ b/PushNotification/www/PushNotification.js @@ -0,0 +1,65 @@ + +var PushNotification = function() { +}; + + +// Call this to register for push notifications. Content of [options] depends on whether we are working with APNS (iOS) or GCM (Android) +PushNotification.prototype.register = function(successCallback, errorCallback, options) { + if (errorCallback == null) { errorCallback = function() {}} + + if (typeof errorCallback != "function") { + console.log("PushNotification.register failure: failure parameter not a function"); + return + } + + if (typeof successCallback != "function") { + console.log("PushNotification.register failure: success callback parameter must be a function"); + return + } + + cordova.exec(successCallback, errorCallback, "PushPlugin", "register", [options]); +}; + +// Call this to unregister for push notifications +PushNotification.prototype.unregister = function(successCallback, errorCallback) { + if (errorCallback == null) { errorCallback = function() {}} + + if (typeof errorCallback != "function") { + console.log("PushNotification.unregister failure: failure parameter not a function"); + return + } + + if (typeof successCallback != "function") { + console.log("PushNotification.unregister failure: success callback parameter must be a function"); + return + } + + cordova.exec(successCallback, errorCallback, "PushPlugin", "unregister", []); +}; + + +// Call this to set the application icon badge +PushNotification.prototype.setApplicationIconBadgeNumber = function(successCallback, badge) { + if (errorCallback == null) { errorCallback = function() {}} + + if (typeof errorCallback != "function") { + console.log("PushNotification.setApplicationIconBadgeNumber failure: failure parameter not a function"); + return + } + + if (typeof successCallback != "function") { + console.log("PushNotification.setApplicationIconBadgeNumber failure: success callback parameter must be a function"); + return + } + + cordova.exec(successCallback, successCallback, "PushPlugin", "setApplicationIconBadgeNumber", [{badge: badge}]); +}; + +//------------------------------------------------------------------- + +if(!window.plugins) { + window.plugins = {}; +} +if (!window.plugins.pushNotification) { + window.plugins.pushNotification = new PushNotification(); +}