Titanium SDK version 3.4.0.GA Targeting Android SDK: 20
Debugging on device running Android 4.4.4
Am able to retrieve deviceToken and can receive push notifications.
But the push notifications show up as an alert only when the application has focus
When the application does not have focus, I get an error that says the application has stopped working.
Sometimes, bringing the application back into focus shows the notifications sent when the application was not in focus.
How do start to debug this, please?
A little fogged - any pointers would be a great help
Many thanks
Iyer
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
var df = require("./dreamfactory");
var promise = require("./Promise");
var winMain = Ti.UI.createWindow({
backgroundColor:"#000",
layout: "vertical"
});
var CloudPush = require('ti.cloudpush');
var deviceTokenLabel = Ti.UI.createLabel({
top: '10dp', width: '320dp', height: (CloudPush.pushType=='gcm'?'150dp':'40dp'),
font: { fontSize:14}, color: 'white',
text: 'Device Token'
});
winMain.add(deviceTokenLabel);
var deviceToken = Ti.App.Properties.getString("deviceToken", "");
if (deviceToken == "") {
CloudPush.retrieveDeviceToken({
success: deviceTokenSuccess,
error: deviceTokenError
});
} else {
deviceTokenLabel.text = 'Already Had Device Token:' + deviceToken;
registerWithDSP();
}
function deviceTokenSuccess(e) {
Ti.API.info('Device Token: ' + e.deviceToken);
deviceTokenLabel.text = 'Device Token:' + e.deviceToken;
Ti.App.Properties.setString('deviceToken', e.deviceToken);
registerWithDSP();
//enablePush.enabled = true;
}
function registerWithDSP() {
var body = {email:"iyer@ndtv.com" , password : "yeggikallie"};
body = JSON.stringify(body);
Ti.API.info(body);
df.makeRequest("post","/user/session", body).then(function(response) {
SESSION_ID = response.session_id;
Ti.API.info("session id " + SESSION_ID);
}, function(error){
Ti.API.info("Could not connect " + error);
});
}
function deviceTokenError(e) {
alert('Failed to register for push! ' + e.error);
deviceTokenLabel.text = 'Failed to get device token.';
}
CloudPush.addEventListener('callback', function (evt) {
alert(evt.payload);
});
CloudPush.addEventListener('trayClickLaunchedApp', function (evt) {
Ti.API.info('Tray Click Launched App (app was not running)');
});
CloudPush.addEventListener('trayClickFocusedApp', function (evt) {
Ti.API.info('Tray Click Focused App (app was already running)');
});
winMain.open();