Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Keep the originals in the iOS project because Xcode isn't able to dea…

…l with symlinks out of the box.
  • Loading branch information...
commit c2a12a5c6a7337fd5d8ffc0d4aee90b716ca681a 1 parent 008337c
@jtowle jtowle authored
View
1  ios-sample/www/index.html
View
314 ios-sample/www/index.html
@@ -0,0 +1,314 @@
+<!DOCTYPE html>
+<html>
+
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>Phonegap Sample App</title>
+
+ <link href="css/jquery.mobile-1.1.1.css" rel="stylesheet" type="text/css"/>
+
+ <script type="text/javascript" src="lib/jquery.js"></script>
+ <script type="text/javascript" src="js/jquery.mobile-1.1.1.js"></script>
+
+ <script type="text/javascript" src="cordova-2.2.0.js"></script>
+ <script type="text/javascript" src="lib/PushNotification.js"></script>
+ <script type="text/javascript">
+
+ function onLoad() {
+ document.addEventListener("deviceready", function() {
+
+ push = window.pushNotification
+
+ // Reset Badge on resume
+ document.addEventListener("resume", function() {
+ push.resetBadge()
+ })
+
+ push.getIncoming(function (incoming) {
+ if(incoming.message) {
+ console.log("Incoming push: " + incoming.message)
+ } else {
+ console.log("No incoming message")
+ }
+ })
+
+ function on_push(data) {
+ console.log("Received push: " + data.message)
+ }
+
+ function on_reg(error, pushID) {
+ if (!error) {
+ console.log("Reg Success: " + pushID)
+ $('#id').text(pushID)
+ }
+ }
+
+ push.registerEvent('registration', on_reg)
+
+ push.registerEvent('push', on_push)
+
+ function add_tag(tag) {
+ $('#tags').prepend("<p>" + tag + "<input type='button' class='removeTagButton' value='Remove' /></p>")
+ //This needs to be here because the element doesn't exist at load.
+ $(".removeTagButton").on("click", function(ev) {
+ p = $(ev.target).parent()
+ tag = p.text()
+ p.remove()
+ push.getTags(function(obj) {
+ console.log("Removing tag: " + tag)
+ obj.tags.splice(obj.tags.indexOf(tag), 1)
+ push.setTags(obj.tags)
+ })
+ })
+ }
+
+ function set_alias(alias) {
+ $("#alias").text(alias)
+ $("#setAliasField").val("")
+ }
+
+ push.isPushEnabled(function(has_push) {
+ if (has_push) {
+ $('#pushEnabled').val('on').change();
+ } else {
+ $('#pushEnabled').val('off').change();
+ }
+ })
+
+ push.isSoundEnabled(function(has_sound) {
+ if (has_sound) {
+ $('#soundEnabled').val('on').change();
+ } else {
+ $('#soundEnabled').val('off').change();
+ }
+ })
+
+ push.isVibrateEnabled(function(has_vibrate) {
+ if (has_vibrate) {
+ $('#vibrateEnabled').val('on').change();
+ } else {
+ $('#vibrateEnabled').val('off').change();
+ }
+ })
+
+ push.isQuietTimeEnabled(function(has_quiettime) {
+ if (has_quiettime) {
+ $('#quietTimeEnabled').val('on').change();
+ } else {
+ $('#quietTimeEnabled').val('off').change();
+ }
+ })
+
+ push.isLocationEnabled(function(enabled) {
+ if (enabled) {
+ $('#locationEnabled').val('on').change();
+ } else {
+ $('#locationEnabled').val('off').change();
+ }
+ })
+
+ $('#pushEnabled').change(function() {
+ if ($('#pushEnabled').val() == "on") {
+ // This means we want to turn it on
+ push.enablePush()
+ } else {
+ push.disablePush()
+ }
+ })
+
+ $('#soundEnabled').change(function() {
+ if ($('#soundEnabled').val() == "on") {
+ //This means we want to turn it on
+ push.setSoundEnabled(true)
+ } else {
+ push.setSoundEnabled(false)
+ }
+ })
+
+ $('#vibrateEnabled').change(function() {
+ if ($('#vibrateEnabled').val() == "on") {
+ //This means we want to turn it on
+ push.setVibrateEnabled(true)
+ } else {
+ push.setVibrateEnabled(false)
+ }
+ })
+
+ $('#quietTimeEnabled').change(function() {
+ if ($('#quietTimeEnabled').val() == "on") {
+ //This means we want to turn it on
+ push.setQuietTimeEnabled(true)
+ } else {
+ push.setQuietTimeEnabled(false)
+ }
+ })
+
+ $('#locationEnabled').change(function() {
+ if ($('#locationEnabled').val() == "on") {
+ //This means we want to turn it on
+ push.enableLocation()
+ } else {
+ push.disableLocation()
+ }
+ })
+
+ $("#addTagButton").click(function(ev) {
+ var new_tag = $("#addTagField").val()
+ console.log("Adding new tag: " + new_tag)
+ push.getTags(function(obj) {
+ if (obj.tags.indexOf(new_tag) == -1) {
+ console.log("Valid tag: " + new_tag)
+ obj.tags = obj.tags.concat([new_tag])
+ push.setTags(obj.tags, function() {
+ add_tag(new_tag)
+ $("#addTagField").val('')
+ })
+ }
+ })
+ })
+
+ $("#setQuietTimeButton").click(function(ev) {
+ var startHour = parseInt($("#startHour").val())
+ var startMinute = parseInt($("#startMinute").val())
+ var endHour = parseInt($("#endHour").val())
+ var endMinute = parseInt($("#endMinute").val())
+
+ push.setQuietTime(startHour, startMinute, endHour, endMinute, function() {
+ console.log("Set quiet time from JS")
+ })
+ })
+
+ $("#setAliasButton").click(function(ev) {
+ var new_alias = $("#setAliasField").val()
+ push.setAlias(new_alias, function() {
+ set_alias(new_alias)
+ })
+ })
+
+ push.getPushID(function (id) {
+ if(id) {
+ console.log("Got push ID: " + id)
+ $('#id').text(id)
+ }
+ })
+
+ push.getAlias(function (alias) {
+ if(alias) {
+ console.log("Got alias: " + alias)
+ set_alias(alias)
+ } else {
+ console.log("No alias");
+ }
+ })
+
+ push.getTags(function(obj) {
+ obj.tags.forEach(function(tag) {
+ add_tag(tag)
+ })
+ })
+
+ push.getQuietTime(function(obj) {
+ $("#startHour").val(obj.startHour)
+ $("#startMinute").val(obj.startMinute)
+ $("#endHour").val(obj.endHour)
+ $("#endMinute").val(obj.endMinute)
+ })
+
+ push.registerForNotificationTypes(push.notificationType.badge | push.notificationType.sound | push.notificationType.alert)
+ if (device.platform != "Android") {
+ $("#soundEnabledSection").hide();
+ $("#vibrateEnabledSection").hide();
+ }
+ })
+ }
+ </script>
+</head>
+ <body onload="onLoad()">
+ <div data-role="page" id="page">
+
+ <div data-role="header" class="ui-bar ui-bar-b">
+ <center>
+ <img border="0" src="img/logo.png" alt="Urban Airship" align="center" />
+ </center>
+ </div>
+
+ <div data-role="content">
+ <form>
+ <div class="ui-body ui-body-b">
+
+ <div data-role="fieldcontain">
+ <label for="id">Identifier:</label><br />
+ <span name="id" id="id" style="word-wrap: break-word;"></span>
+ <center><h3>Push Settings</h3></center>
+ <label>Alias: </label>
+ <span name="alias" id="alias"></span><hr />
+ <input type="text" name="setAliasField" id="setAliasField" style="width:96.5%;" /> <input type="button" id="setAliasButton" value="Set alias" />
+ </div>
+
+ <div data-role="controlgroup">
+ <label for="pushEnabled">Push Enabled</label>
+ <select name="pushEnabled" id="pushEnabled" data-role="slider" data-theme="c" data-track-theme="c">
+ <option value="off">Off</option>
+ <option value="on">On</option>
+ </select>
+ </div>
+
+ <div data-role="controlgroup">
+ <span id="soundEnabledSection">
+ <label for="soundEnabled">Sound Enabled</label>
+ <select name="soundEnabled" id="soundEnabled" data-role="slider" data-theme="c" data-track-theme="c">
+ <option value="off">Off</option>
+ <option value="on">On</option>
+ </select>
+ </span>
+ </div>
+
+ <div data-role="controlgroup">
+ <span id="vibrateEnabledSection">
+ <label for="vibrateEnabled">Vibrate Enabled</label>
+ <select name="vibrateEnabled" id="vibrateEnabled" data-role="slider" data-theme="c" data-track-theme="c">
+ <option value="off">Off</option>
+ <option value="on">On</option>
+ </select>
+ </span>
+ </div>
+
+ <div data-role="controlgroup">
+ <label for="locationEnabled">Location Enabled</label>
+ <select name="locationEnabled" id="locationEnabled" data-role="slider" data-theme="c" data-track-theme="c">
+ <option value="off">Off</option>
+ <option value="on">On</option>
+ </select>
+ </div>
+
+ <div data-role="controlgroup">
+ <label for="quietTimeEnabled">Quiet Time Enabled</label>
+ <span id="quietTimeEnabledSection">
+ <select name="quietTimeEnabled" id="quietTimeEnabled" data-role="slider" data-theme="c" data-track-theme="c">
+ <option value="off">Off</option>
+ <option value="on">On</option>
+ </select>
+ </span>
+ </div>
+
+ <div data-role="fieldcontain">
+ <label for="startHour">Start Time (24h)</label>
+ <input name="startHour" style="width: 3em; margin-left: -5px;" id="startHour" />:<input name="startMinute" style="width: 3em;" id="startMinute" /><br />
+ <label for="startHour">End Time (24h)</label>
+ <input name="endHour" style="width: 3em;" id="endHour" />:<input name="endMinute" style="width: 3em;" id="endMinute" />
+ <input type="button" id="setQuietTimeButton" value="Set Quiet Time" />
+ </div>
+
+ <div data-role="fieldcontain">
+ <input name="addTagField" id="addTagField" />
+ <input type="button" id="addTagButton" value="Add tag" />
+ <div id="tags"></div>
+ </div>
+
+ </div>
+ </form>
+ </div>
+
+ </div>
+</body>
+</html>
View
262 ios-sample/www/lib/PushNotification.js
@@ -0,0 +1,262 @@
+// Event emitter used to raise events from the library.
+function EventEmitter() {
+ this._listeners = {}
+ this._mutators = {}
+}
+
+var cons = EventEmitter
+ , proto = cons.prototype
+
+proto.on = function(ev, fn) {
+ (this._listeners[ev] = this._listeners[ev] || []).push(fn)
+ return this
+}
+
+proto.mutate = function(ev, fn) {
+ this._mutators[ev] = fn
+ return this
+}
+
+proto.once = function(ev, fn) {
+ var self = this
+ return self.on(ev, listener)
+
+ function listener() {
+ fn.apply(this, [].slice.call(arguments))
+ self.remove(ev, listener)
+ }
+}
+
+proto.emit = function(ev) {
+ var list = this._listeners[ev] || []
+ , args = [].slice.call(arguments, 1)
+ , mutator = this._mutators[ev] || function() { return [].slice.call(arguments) }
+
+ args = mutator.apply(null, args)
+
+ list.forEach(function(fn) {
+ fn.apply(null, args)
+ })
+}
+
+proto.listeners = function(ev) {
+ return this._listeners[ev] || []
+}
+
+proto.removeListener =
+proto.remove = function(ev, fn) {
+ var tmp = this._listeners[ev] || []
+
+ typeof fn === 'function' ?
+ tmp.indexOf(fn) > -1 && tmp.splice(tmp.indexOf(fn), 1) :
+ delete this._listeners[ev]
+}
+
+// Init the plugin
+var PushNotification = function () {
+ this.event_emitter = new EventEmitter
+ };
+
+// Types
+
+PushNotification.prototype.notificationType = {
+ none: 0,
+ badge: 1,
+ sound: 2,
+ alert: 4
+}
+
+// Helpers
+
+PushNotification.prototype.failure = function (msg) {
+ console.log("Javascript Callback Error: " + msg)
+}
+
+
+PushNotification.prototype.call_native = function (callback, name, args) {
+ if(arguments.length == 2) {
+ args = []
+ }
+ ret = cordova.exec(
+ callback, // called when signature capture is successful
+ this.failure, // called when signature capture encounters an error
+ 'PushNotificationPlugin', // Tell cordova that we want to run "PushNotificationPlugin"
+ name, // Tell the plugin the action we want to perform
+ args); // List of arguments to the plugin
+ return ret;
+}
+
+PushNotification.prototype.isPlatformIOS = function () {
+ return device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch" || device.platform == "iOS"
+}
+
+// Core API
+
+// Registration
+
+PushNotification.prototype.registerForNotificationTypes = function (types, callback) {
+ if(device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch" || device.platform == "iOS") {
+ this.call_native(callback, "registerForNotificationTypes", [types])
+ }
+}
+
+// Top level enabling/disabling
+
+PushNotification.prototype.enablePush = function (callback) {
+ this.call_native(callback, "enablePush");
+}
+
+PushNotification.prototype.disablePush = function (callback) {
+ this.call_native(callback, "disablePush");
+}
+
+PushNotification.prototype.enableLocation = function (callback) {
+ this.call_native(callback, "enableLocation")
+}
+
+PushNotification.prototype.disableLocation = function (callback) {
+ this.call_native(callback, "disableLocation")
+}
+
+PushNotification.prototype.enableBackgroundLocation = function (callback) {
+ this.call_native(callback, "enableBackgroundLocation")
+}
+
+PushNotification.prototype.disableBackgroundLocation = function (callback) {
+ this.call_native(callback, "disableBackgroundLocation")
+}
+
+// is* functions
+
+PushNotification.prototype.isPushEnabled = function (callback) {
+ this.call_native(callback, "isPushEnabled");
+}
+
+PushNotification.prototype.isSoundEnabled = function (callback) {
+ if(device.platform == "Android") {
+ this.call_native(callback, "isSoundEnabled");
+ }
+}
+
+PushNotification.prototype.isVibrateEnabled = function (callback) {
+ if(device.platform == "Android") {
+ this.call_native(callback, "isVibrateEnabled");
+ }
+}
+
+PushNotification.prototype.isQuietTimeEnabled = function (callback) {
+ this.call_native(callback, "isQuietTimeEnabled");
+}
+
+PushNotification.prototype.isInQuietTime = function (callback) {
+ this.call_native(callback, "isInQuietTime");
+}
+
+PushNotification.prototype.isLocationEnabled = function (callback) {
+ this.call_native(callback, "isLocationEnabled");
+}
+
+PushNotification.prototype.isBackgroundLocationEnabled = function (callback) {
+ this.call_native(callback, "isBackgroundLocationEnabled");
+}
+
+// Getters
+
+PushNotification.prototype.getIncoming = function (callback) {
+ this.call_native(callback, "getIncoming");
+}
+
+PushNotification.prototype.getPushID = function (callback) {
+ this.call_native(callback, "getPushID")
+}
+
+PushNotification.prototype.getQuietTime = function (callback) {
+ this.call_native(callback, "getQuietTime");
+}
+
+PushNotification.prototype.getTags = function (callback) {
+ this.call_native(callback, "getTags");
+}
+
+PushNotification.prototype.getAlias = function (callback) {
+ this.call_native(callback, "getAlias");
+}
+
+// Setters
+
+PushNotification.prototype.setAlias = function (alias, callback) {
+ this.call_native(callback, "setAlias", [alias])
+}
+
+PushNotification.prototype.setTags = function (tags, callback) {
+ this.call_native(callback, "setTags", [tags])
+}
+
+PushNotification.prototype.setSoundEnabled = function (bool, callback) {
+ if(device.platform == "Android") {
+ this.call_native(callback, "setSoundEnabled", [bool])
+ }
+}
+
+PushNotification.prototype.setVibrateEnabled = function (bool, callback) {
+ if(device.platform == "Android") {
+ this.call_native(callback, "setVibrateEnabled", [bool])
+ }
+}
+
+PushNotification.prototype.setQuietTimeEnabled = function (bool, callback) {
+ this.call_native(callback, "setQuietTimeEnabled", [bool])
+}
+
+PushNotification.prototype.setQuietTime = function (startHour, startMinute, endHour, endMinute, callback) {
+ this.call_native(callback, "setQuietTime", [startHour, startMinute, endHour, endMinute])
+}
+
+PushNotification.prototype.setAutobadgeEnabled = function (enabled, callback) {
+ if (this.isPlatformIOS()) {
+ this.call_native(callback, "setAutobadgeEnabled", [enabled]);
+ }
+}
+
+PushNotification.prototype.setBadgeNumber = function (number, callback) {
+ if (this.isPlatformIOS()) {
+ this.call_native(callback, "setBadgeNumber", [number]);
+ }
+}
+
+// Reset Badge
+
+PushNotification.prototype.resetBadge = function (callback) {
+ if (this.isPlatformIOS()) {
+ this.call_native(callback, "resetBadge");
+ }
+}
+
+// Location stuff
+
+PushNotification.prototype.recordCurrentLocation = function (callback) {
+ this.call_native(callback, "recordCurrentLocation");
+}
+
+// Event handling stuff (INTERNAL)
+
+PushNotification.prototype.registerEvent = function (event, func) {
+ // Do event name validation?
+ this.event_emitter.on(event, func)
+}
+
+PushNotification.prototype.pushCallback = function (data) {
+ this.event_emitter.emit('push', data);
+}
+
+PushNotification.prototype.registrationCallback = function (data) {
+ error = !data['valid'];
+ pushID = data['pushID'];
+ this.event_emitter.emit('registration', error, pushID);
+}
+
+// Register the plugin
+
+cordova.addConstructor(function () {
+ window.pushNotification = new PushNotification();
+});
View
1  ios-sample/www/lib/PushNotification.js
View
1  plugin-common/PushNotification.js
View
262 plugin-common/PushNotification.js
@@ -1,262 +0,0 @@
-// Event emitter used to raise events from the library.
-function EventEmitter() {
- this._listeners = {}
- this._mutators = {}
-}
-
-var cons = EventEmitter
- , proto = cons.prototype
-
-proto.on = function(ev, fn) {
- (this._listeners[ev] = this._listeners[ev] || []).push(fn)
- return this
-}
-
-proto.mutate = function(ev, fn) {
- this._mutators[ev] = fn
- return this
-}
-
-proto.once = function(ev, fn) {
- var self = this
- return self.on(ev, listener)
-
- function listener() {
- fn.apply(this, [].slice.call(arguments))
- self.remove(ev, listener)
- }
-}
-
-proto.emit = function(ev) {
- var list = this._listeners[ev] || []
- , args = [].slice.call(arguments, 1)
- , mutator = this._mutators[ev] || function() { return [].slice.call(arguments) }
-
- args = mutator.apply(null, args)
-
- list.forEach(function(fn) {
- fn.apply(null, args)
- })
-}
-
-proto.listeners = function(ev) {
- return this._listeners[ev] || []
-}
-
-proto.removeListener =
-proto.remove = function(ev, fn) {
- var tmp = this._listeners[ev] || []
-
- typeof fn === 'function' ?
- tmp.indexOf(fn) > -1 && tmp.splice(tmp.indexOf(fn), 1) :
- delete this._listeners[ev]
-}
-
-// Init the plugin
-var PushNotification = function () {
- this.event_emitter = new EventEmitter
- };
-
-// Types
-
-PushNotification.prototype.notificationType = {
- none: 0,
- badge: 1,
- sound: 2,
- alert: 4
-}
-
-// Helpers
-
-PushNotification.prototype.failure = function (msg) {
- console.log("Javascript Callback Error: " + msg)
-}
-
-
-PushNotification.prototype.call_native = function (callback, name, args) {
- if(arguments.length == 2) {
- args = []
- }
- ret = cordova.exec(
- callback, // called when signature capture is successful
- this.failure, // called when signature capture encounters an error
- 'PushNotificationPlugin', // Tell cordova that we want to run "PushNotificationPlugin"
- name, // Tell the plugin the action we want to perform
- args); // List of arguments to the plugin
- return ret;
-}
-
-PushNotification.prototype.isPlatformIOS = function () {
- return device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch" || device.platform == "iOS"
-}
-
-// Core API
-
-// Registration
-
-PushNotification.prototype.registerForNotificationTypes = function (types, callback) {
- if(device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch" || device.platform == "iOS") {
- this.call_native(callback, "registerForNotificationTypes", [types])
- }
-}
-
-// Top level enabling/disabling
-
-PushNotification.prototype.enablePush = function (callback) {
- this.call_native(callback, "enablePush");
-}
-
-PushNotification.prototype.disablePush = function (callback) {
- this.call_native(callback, "disablePush");
-}
-
-PushNotification.prototype.enableLocation = function (callback) {
- this.call_native(callback, "enableLocation")
-}
-
-PushNotification.prototype.disableLocation = function (callback) {
- this.call_native(callback, "disableLocation")
-}
-
-PushNotification.prototype.enableBackgroundLocation = function (callback) {
- this.call_native(callback, "enableBackgroundLocation")
-}
-
-PushNotification.prototype.disableBackgroundLocation = function (callback) {
- this.call_native(callback, "disableBackgroundLocation")
-}
-
-// is* functions
-
-PushNotification.prototype.isPushEnabled = function (callback) {
- this.call_native(callback, "isPushEnabled");
-}
-
-PushNotification.prototype.isSoundEnabled = function (callback) {
- if(device.platform == "Android") {
- this.call_native(callback, "isSoundEnabled");
- }
-}
-
-PushNotification.prototype.isVibrateEnabled = function (callback) {
- if(device.platform == "Android") {
- this.call_native(callback, "isVibrateEnabled");
- }
-}
-
-PushNotification.prototype.isQuietTimeEnabled = function (callback) {
- this.call_native(callback, "isQuietTimeEnabled");
-}
-
-PushNotification.prototype.isInQuietTime = function (callback) {
- this.call_native(callback, "isInQuietTime");
-}
-
-PushNotification.prototype.isLocationEnabled = function (callback) {
- this.call_native(callback, "isLocationEnabled");
-}
-
-PushNotification.prototype.isBackgroundLocationEnabled = function (callback) {
- this.call_native(callback, "isBackgroundLocationEnabled");
-}
-
-// Getters
-
-PushNotification.prototype.getIncoming = function (callback) {
- this.call_native(callback, "getIncoming");
-}
-
-PushNotification.prototype.getPushID = function (callback) {
- this.call_native(callback, "getPushID")
-}
-
-PushNotification.prototype.getQuietTime = function (callback) {
- this.call_native(callback, "getQuietTime");
-}
-
-PushNotification.prototype.getTags = function (callback) {
- this.call_native(callback, "getTags");
-}
-
-PushNotification.prototype.getAlias = function (callback) {
- this.call_native(callback, "getAlias");
-}
-
-// Setters
-
-PushNotification.prototype.setAlias = function (alias, callback) {
- this.call_native(callback, "setAlias", [alias])
-}
-
-PushNotification.prototype.setTags = function (tags, callback) {
- this.call_native(callback, "setTags", [tags])
-}
-
-PushNotification.prototype.setSoundEnabled = function (bool, callback) {
- if(device.platform == "Android") {
- this.call_native(callback, "setSoundEnabled", [bool])
- }
-}
-
-PushNotification.prototype.setVibrateEnabled = function (bool, callback) {
- if(device.platform == "Android") {
- this.call_native(callback, "setVibrateEnabled", [bool])
- }
-}
-
-PushNotification.prototype.setQuietTimeEnabled = function (bool, callback) {
- this.call_native(callback, "setQuietTimeEnabled", [bool])
-}
-
-PushNotification.prototype.setQuietTime = function (startHour, startMinute, endHour, endMinute, callback) {
- this.call_native(callback, "setQuietTime", [startHour, startMinute, endHour, endMinute])
-}
-
-PushNotification.prototype.setAutobadgeEnabled = function (enabled, callback) {
- if (this.isPlatformIOS()) {
- this.call_native(callback, "setAutobadgeEnabled", [enabled]);
- }
-}
-
-PushNotification.prototype.setBadgeNumber = function (number, callback) {
- if (this.isPlatformIOS()) {
- this.call_native(callback, "setBadgeNumber", [number]);
- }
-}
-
-// Reset Badge
-
-PushNotification.prototype.resetBadge = function (callback) {
- if (this.isPlatformIOS()) {
- this.call_native(callback, "resetBadge");
- }
-}
-
-// Location stuff
-
-PushNotification.prototype.recordCurrentLocation = function (callback) {
- this.call_native(callback, "recordCurrentLocation");
-}
-
-// Event handling stuff (INTERNAL)
-
-PushNotification.prototype.registerEvent = function (event, func) {
- // Do event name validation?
- this.event_emitter.on(event, func)
-}
-
-PushNotification.prototype.pushCallback = function (data) {
- this.event_emitter.emit('push', data);
-}
-
-PushNotification.prototype.registrationCallback = function (data) {
- error = !data['valid'];
- pushID = data['pushID'];
- this.event_emitter.emit('registration', error, pushID);
-}
-
-// Register the plugin
-
-cordova.addConstructor(function () {
- window.pushNotification = new PushNotification();
-});
View
314 plugin-common/index.html
@@ -1,314 +0,0 @@
-<!DOCTYPE html>
-<html>
-
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>Phonegap Sample App</title>
-
- <link href="css/jquery.mobile-1.1.1.css" rel="stylesheet" type="text/css"/>
-
- <script type="text/javascript" src="lib/jquery.js"></script>
- <script type="text/javascript" src="js/jquery.mobile-1.1.1.js"></script>
-
- <script type="text/javascript" src="cordova-2.2.0.js"></script>
- <script type="text/javascript" src="lib/PushNotification.js"></script>
- <script type="text/javascript">
-
- function onLoad() {
- document.addEventListener("deviceready", function() {
-
- push = window.pushNotification
-
- // Reset Badge on resume
- document.addEventListener("resume", function() {
- push.resetBadge()
- })
-
- push.getIncoming(function (incoming) {
- if(incoming.message) {
- console.log("Incoming push: " + incoming.message)
- } else {
- console.log("No incoming message")
- }
- })
-
- function on_push(data) {
- console.log("Received push: " + data.message)
- }
-
- function on_reg(error, pushID) {
- if (!error) {
- console.log("Reg Success: " + pushID)
- $('#id').text(pushID)
- }
- }
-
- push.registerEvent('registration', on_reg)
-
- push.registerEvent('push', on_push)
-
- function add_tag(tag) {
- $('#tags').prepend("<p>" + tag + "<input type='button' class='removeTagButton' value='Remove' /></p>")
- //This needs to be here because the element doesn't exist at load.
- $(".removeTagButton").on("click", function(ev) {
- p = $(ev.target).parent()
- tag = p.text()
- p.remove()
- push.getTags(function(obj) {
- console.log("Removing tag: " + tag)
- obj.tags.splice(obj.tags.indexOf(tag), 1)
- push.setTags(obj.tags)
- })
- })
- }
-
- function set_alias(alias) {
- $("#alias").text(alias)
- $("#setAliasField").val("")
- }
-
- push.isPushEnabled(function(has_push) {
- if (has_push) {
- $('#pushEnabled').val('on').change();
- } else {
- $('#pushEnabled').val('off').change();
- }
- })
-
- push.isSoundEnabled(function(has_sound) {
- if (has_sound) {
- $('#soundEnabled').val('on').change();
- } else {
- $('#soundEnabled').val('off').change();
- }
- })
-
- push.isVibrateEnabled(function(has_vibrate) {
- if (has_vibrate) {
- $('#vibrateEnabled').val('on').change();
- } else {
- $('#vibrateEnabled').val('off').change();
- }
- })
-
- push.isQuietTimeEnabled(function(has_quiettime) {
- if (has_quiettime) {
- $('#quietTimeEnabled').val('on').change();
- } else {
- $('#quietTimeEnabled').val('off').change();
- }
- })
-
- push.isLocationEnabled(function(enabled) {
- if (enabled) {
- $('#locationEnabled').val('on').change();
- } else {
- $('#locationEnabled').val('off').change();
- }
- })
-
- $('#pushEnabled').change(function() {
- if ($('#pushEnabled').val() == "on") {
- // This means we want to turn it on
- push.enablePush()
- } else {
- push.disablePush()
- }
- })
-
- $('#soundEnabled').change(function() {
- if ($('#soundEnabled').val() == "on") {
- //This means we want to turn it on
- push.setSoundEnabled(true)
- } else {
- push.setSoundEnabled(false)
- }
- })
-
- $('#vibrateEnabled').change(function() {
- if ($('#vibrateEnabled').val() == "on") {
- //This means we want to turn it on
- push.setVibrateEnabled(true)
- } else {
- push.setVibrateEnabled(false)
- }
- })
-
- $('#quietTimeEnabled').change(function() {
- if ($('#quietTimeEnabled').val() == "on") {
- //This means we want to turn it on
- push.setQuietTimeEnabled(true)
- } else {
- push.setQuietTimeEnabled(false)
- }
- })
-
- $('#locationEnabled').change(function() {
- if ($('#locationEnabled').val() == "on") {
- //This means we want to turn it on
- push.enableLocation()
- } else {
- push.disableLocation()
- }
- })
-
- $("#addTagButton").click(function(ev) {
- var new_tag = $("#addTagField").val()
- console.log("Adding new tag: " + new_tag)
- push.getTags(function(obj) {
- if (obj.tags.indexOf(new_tag) == -1) {
- console.log("Valid tag: " + new_tag)
- obj.tags = obj.tags.concat([new_tag])
- push.setTags(obj.tags, function() {
- add_tag(new_tag)
- $("#addTagField").val('')
- })
- }
- })
- })
-
- $("#setQuietTimeButton").click(function(ev) {
- var startHour = parseInt($("#startHour").val())
- var startMinute = parseInt($("#startMinute").val())
- var endHour = parseInt($("#endHour").val())
- var endMinute = parseInt($("#endMinute").val())
-
- push.setQuietTime(startHour, startMinute, endHour, endMinute, function() {
- console.log("Set quiet time from JS")
- })
- })
-
- $("#setAliasButton").click(function(ev) {
- var new_alias = $("#setAliasField").val()
- push.setAlias(new_alias, function() {
- set_alias(new_alias)
- })
- })
-
- push.getPushID(function (id) {
- if(id) {
- console.log("Got push ID: " + id)
- $('#id').text(id)
- }
- })
-
- push.getAlias(function (alias) {
- if(alias) {
- console.log("Got alias: " + alias)
- set_alias(alias)
- } else {
- console.log("No alias");
- }
- })
-
- push.getTags(function(obj) {
- obj.tags.forEach(function(tag) {
- add_tag(tag)
- })
- })
-
- push.getQuietTime(function(obj) {
- $("#startHour").val(obj.startHour)
- $("#startMinute").val(obj.startMinute)
- $("#endHour").val(obj.endHour)
- $("#endMinute").val(obj.endMinute)
- })
-
- push.registerForNotificationTypes(push.notificationType.badge | push.notificationType.sound | push.notificationType.alert)
- if (device.platform != "Android") {
- $("#soundEnabledSection").hide();
- $("#vibrateEnabledSection").hide();
- }
- })
- }
- </script>
-</head>
- <body onload="onLoad()">
- <div data-role="page" id="page">
-
- <div data-role="header" class="ui-bar ui-bar-b">
- <center>
- <img border="0" src="img/logo.png" alt="Urban Airship" align="center" />
- </center>
- </div>
-
- <div data-role="content">
- <form>
- <div class="ui-body ui-body-b">
-
- <div data-role="fieldcontain">
- <label for="id">Identifier:</label><br />
- <span name="id" id="id" style="word-wrap: break-word;"></span>
- <center><h3>Push Settings</h3></center>
- <label>Alias: </label>
- <span name="alias" id="alias"></span><hr />
- <input type="text" name="setAliasField" id="setAliasField" style="width:96.5%;" /> <input type="button" id="setAliasButton" value="Set alias" />
- </div>
-
- <div data-role="controlgroup">
- <label for="pushEnabled">Push Enabled</label>
- <select name="pushEnabled" id="pushEnabled" data-role="slider" data-theme="c" data-track-theme="c">
- <option value="off">Off</option>
- <option value="on">On</option>
- </select>
- </div>
-
- <div data-role="controlgroup">
- <span id="soundEnabledSection">
- <label for="soundEnabled">Sound Enabled</label>
- <select name="soundEnabled" id="soundEnabled" data-role="slider" data-theme="c" data-track-theme="c">
- <option value="off">Off</option>
- <option value="on">On</option>
- </select>
- </span>
- </div>
-
- <div data-role="controlgroup">
- <span id="vibrateEnabledSection">
- <label for="vibrateEnabled">Vibrate Enabled</label>
- <select name="vibrateEnabled" id="vibrateEnabled" data-role="slider" data-theme="c" data-track-theme="c">
- <option value="off">Off</option>
- <option value="on">On</option>
- </select>
- </span>
- </div>
-
- <div data-role="controlgroup">
- <label for="locationEnabled">Location Enabled</label>
- <select name="locationEnabled" id="locationEnabled" data-role="slider" data-theme="c" data-track-theme="c">
- <option value="off">Off</option>
- <option value="on">On</option>
- </select>
- </div>
-
- <div data-role="controlgroup">
- <label for="quietTimeEnabled">Quiet Time Enabled</label>
- <span id="quietTimeEnabledSection">
- <select name="quietTimeEnabled" id="quietTimeEnabled" data-role="slider" data-theme="c" data-track-theme="c">
- <option value="off">Off</option>
- <option value="on">On</option>
- </select>
- </span>
- </div>
-
- <div data-role="fieldcontain">
- <label for="startHour">Start Time (24h)</label>
- <input name="startHour" style="width: 3em; margin-left: -5px;" id="startHour" />:<input name="startMinute" style="width: 3em;" id="startMinute" /><br />
- <label for="startHour">End Time (24h)</label>
- <input name="endHour" style="width: 3em;" id="endHour" />:<input name="endMinute" style="width: 3em;" id="endMinute" />
- <input type="button" id="setQuietTimeButton" value="Set Quiet Time" />
- </div>
-
- <div data-role="fieldcontain">
- <input name="addTagField" id="addTagField" />
- <input type="button" id="addTagButton" value="Add tag" />
- <div id="tags"></div>
- </div>
-
- </div>
- </form>
- </div>
-
- </div>
-</body>
-</html>
View
1  plugin-common/index.html
Please sign in to comment.
Something went wrong with that request. Please try again.