Skip to content

Instantly share code, notes, and snippets.

@opolyo01
Created March 19, 2013 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opolyo01/5197701 to your computer and use it in GitHub Desktop.
Save opolyo01/5197701 to your computer and use it in GitHub Desktop.
Push Notifications with Titanium Cloud
getDeviceToken();
function getDeviceToken() {
trace("REGISTERING LOCAL PUSH");
Titanium.Network.registerForPushNotifications({
types : [Titanium.Network.NOTIFICATION_TYPE_BADGE, Titanium.Network.NOTIFICATION_TYPE_ALERT, Titanium.Network.NOTIFICATION_TYPE_SOUND],
success : function(e) {
user_device_token = e.deviceToken;
Ti.App.Properties.setString("device_token", user_device_token);
alert("Device token received " + user_device_token);
login(subscribeToServerPush);
},
error : function(e) {
alert("Error during registration: " + e.error);
},
callback : function(e) {
// called when a push notification is received.
alert("Received a push notification\n\nPayload:\n\n" + JSON.stringify(e.data));
}
});
}
function login(cb) {
var params = {
"login": 'test@yahoo.com',
"password": 'test'
};
Cloud.Users.login(params, function(e) {
if (e.success) {
var user = e.users[0];
alert('Success:\\n' + 'id: ' + user.id + '\\n' + 'first name: ' + user.first_name + '\\n' + 'last name: ' + user.last_name);
cb.call(this);
} else {
alert('Error:\\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
}
function subscribeToServerPush() {
Cloud.PushNotifications.subscribe({
channel : 'friend_request',
type : 'ios',
device_token : user_device_token
}, function(e) {
if (e.success) {
alert('Success' + ((e.error && e.message) || JSON.stringify(e)));
} else {
alert('Error:\\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
}
@ricardosauceda8
Copy link

Sorry I'm also struggling with this, you think it fails platform?
Do not give me access to the cloud.
Your code is to send Push Notifications from a real web server?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment