Created
August 31, 2012 15:20
-
-
Save grantges/3554455 to your computer and use it in GitHub Desktop.
Registering for Push Notifications in Titanium and subscribing to an Appcelerator ACS Push Notification Channel
This file contains 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
var Cloud = require('ti.cloud'); | |
Cloud.debug = true; | |
Cloud.PushNotifications.notify({ | |
channel: 'car-checkout', | |
payload: {alert:'Pending Car Checkout Request', badge:1, car_id: e.rowData.car_id}, // car_id is custom prop | |
to_ids: '123456,78910' | |
}, function (e) { | |
if (e.success) { | |
alert('Your Request has been sent'); | |
Ti.API.debug(JSON.stringify(e)); | |
} else { | |
alert('Error:\\n' + ((e.error && e.message) || JSON.stringify(e))); | |
} | |
}); |
This file contains 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
Ti.Network.registerForPushNotifications({ | |
success: function(e){ | |
Ti.API.debug('PushNotification::DeviceToken: '+e.deviceToken); | |
var Cloud = require('ti.cloud'); | |
Cloud.PushNotifications.subscribe({ | |
channel: 'alert', | |
device_token: e.deviceToken, | |
type: 'ios' | |
}, function (e) { | |
if (e.success) { | |
Ti.API.debug('Successfully registered with channel: alert'); | |
} else { | |
alert('Error:\\n' + ((e.error && e.message) || JSON.stringify(e))); | |
} | |
}); | |
}, | |
error: function(e){ | |
alert('Failed to Register device for notifications - ' + e.error); | |
}, | |
callback: function(e){ | |
/* CODE TO HANDLE INCOMING PUSH NOTIFICATIONS GOES HERE */ | |
Ti.API.info('PushNotification::Data - ' +JSON.stringify(e.data)); | |
Ti.UI.iPhone.appBadge+=1; | |
}, | |
types: [ | |
Titanium.Network.NOTIFICATION_TYPE_BADGE, | |
Titanium.Network.NOTIFICATION_TYPE_ALERT, | |
Titanium.Network.NOTIFICATION_TYPE_SOUND | |
]}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment