summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/www/js/lib/etc/push.js
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/platforms/ios/www/js/lib/etc/push.js')
-rwxr-xr-xStoneIsland/platforms/ios/www/js/lib/etc/push.js70
1 files changed, 69 insertions, 1 deletions
diff --git a/StoneIsland/platforms/ios/www/js/lib/etc/push.js b/StoneIsland/platforms/ios/www/js/lib/etc/push.js
index ab0c0141..eb0dd4c3 100755
--- a/StoneIsland/platforms/ios/www/js/lib/etc/push.js
+++ b/StoneIsland/platforms/ios/www/js/lib/etc/push.js
@@ -1 +1,69 @@
-// \ No newline at end of file
+var push = (function(){
+ var appId
+ var clientKey
+ var push = { settings: {} }
+ push.init = function(){
+ parsePlugin.initialize(appId, clientKey, push.did_initialize, push.error)
+ }
+ push.did_initialize = function() {
+ parsePlugin.registerCallback('onNotification', function(){
+ window.onNotification = push.got_push_notification
+ }, push.error)
+
+ push.settings.requested = localStorage.getItem("yoox.push_requested") == "true"
+ push.settings.hub = localStorage.getItem("yoox.push_hub") == "true"
+ push.settings.store = localStorage.getItem("yoox.push_store") == "true"
+
+ if ( ! push.settings.requested ) {
+ localStorage.setItem("yoox.push_" + channel, "true")
+ push.subscribe("hub", function(){
+ push.subscribe("store")
+ })
+ }
+ }
+ push.subscribe = function(channel, cb){
+ parsePlugin.subscribe(channel, function(){
+ push.settings[channel] = true
+ localStorage.setItem("yoox.push_" + channel, "true")
+ cb && cb()
+ }, push.error)
+ }
+ push.unsubscribe = function(channel, cb){
+ parsePlugin.unsubscribe(channel, function(){
+ push.settings[channel] = false
+ localStorage.setItem("yoox.push_" + channel, "false")
+ cb && cb()
+ }, push.error)
+ }
+ push.did_subscribe = function(){
+ // parsePlugin.getInstallationId(function(id) {
+ // var install_data = {
+ // installation_id: id,
+ // channels: ['SampleChannel']
+ // }
+ // }, push.error)
+ }
+ push.did_unsubscribe = function(){
+ // parsePlugin.getInstallationId(function(id) {
+ // var install_data = {
+ // installation_id: id,
+ // channels: ['SampleChannel']
+ // }
+ // }, push.error)
+ }
+ push.got_push_notification = function(pnObj) {
+ alert('We received this push notification: ' + JSON.stringify(pnObj));
+ app.collection.loaded = false
+ app.hub.loaded = false
+ if (pnObj.receivedInForeground === false) {
+ // TODO: route the user to the uri in pnObj
+ }
+ else {
+ app.route("intro")
+ }
+ }
+ push.error = function(e){
+ console.log("push error")
+ }
+ return push
+})() \ No newline at end of file