Hi, i´m having a strange behavior with my app. When i install it, the first time it wont receive the push notifications from the cloud. But if i restart my application it will work like a charm. The part of the code where i do everthing about it is here.
if(Ti.Platform.osname == "android") { var CloudPush = require('ti.cloudpush'); //CloudPush.debug = true; CloudPush.setEnabled(true); CloudPush.addEventListener('callback', listen); var deviceToken var Cloud = require('ti.cloud'); Cloud.debug = true; CloudPush.retrieveDeviceToken({ success : function deviceTokenSuccess(e) { //alert('Device Token: ' + e.deviceToken); deviceToken = e.deviceToken loginDefault(); }, error : function deviceTokenError(e) { alert('Failed to register for push! ' + e.error); } }); function loginDefault(e) { Cloud.Users.login({ login : '1234', password : '1234' }, function(e) { if(e.success) { defaultSubscribe(); } else { alert('ErrorLogin:\\n' + ((e.error && e.message) || JSON.stringify(e))); } }); } function defaultSubscribe() { Cloud.PushNotifications.subscribe({ channel : 'alert', device_token : deviceToken, type : 'android' }, function(e) { if(e.success) { // alert('Subscribed!'); } else { //CloudPush.addEventListener('callback', listen); // alert('ErrorSubscribe:' +((e.error && e.message) || JSON.stringify(e))); } }); } function defaultUnsubscribe() { Cloud.PushNotifications.unsubscribe({ channel : 'alert', device_token : deviceToken, }, function(e) { if(e.success) { // alert('Subscribed!'); } else { //CloudPush.addEventListener('callback', listen); // alert('ErrorSubscribe:' +((e.error && e.message) || JSON.stringify(e))); } }); } //var CloudPush = require('ti.cloudpush'); // CloudPush.debug = true; //CloudPush.enabled = true; function listen(evt) { var arr_from_json = JSON.parse(evt.payload); //alert(arr_from_json); var dialog = Ti.UI.createAlertDialog({ message : arr_from_json['android'].alert, ok : 'OK', title : arr_from_json['android'].title }).show(); } }I´m really confused, i really don know what to do anymore.
3 Answers
Hi Newton, I'm also quite confused, I'm getting the very same problem as you are. Could anyone please give us a light? Have any of you experienced such behavior? I use the latest Titanium Studio and Android 2.3.3 to deploy it, but even testing in more than 6 different devices it does not work. Best, Joseandro Luiz
Can you please try to set CloudPush enabled after getting device token? Without a proper device token, push service cannot be started correctly.
Hi Newton,
Titanium 2.0.1 have some problem in Cloud Push Notification, so better you could use Titanium 2.0.2. Hope surely you will get result. You can follow this tutorial for Cloud Push Notification Implementation http://www.titaniumtutorial.com/2012/06/appcelerator-cloud-push-notification-in.html
Here you can see Titanium Mobile 2.0.2GA Release Notes for more info
Hope this helps you
Your Answer
Think you can help? Login to answer this question!