Reproduce Step
1. Run the following code in app.js
var win = Ti.UI.createWindow({});
var CloudPush = require('ti.cloudpush');
var Cloud = require('ti.cloud');
var deviceToken = null;
CloudPush.singleCallback = true;
CloudPush.retrieveDeviceToken({
success: function deviceTokenSuccess(e) {
deviceToken = e.deviceToken;
Ti.API.info('Device Token: ' + e.deviceToken);
loginUser();
},
error: function deviceTokenError(e) {
alert('Failed to register for push! ' + e.error);
}
});
CloudPush.addEventListener('callback', function (evt) {
alert(evt.payload);
Ti.API.info("CallBack fired: \n" + evt.payload);
});
CloudPush.addEventListener('trayClickLaunchedApp', function (evt) {
alert('Tray Click Launched App (app was not running)');
Ti.API.info('Tray Click Launched App (app was not running)');
});
CloudPush.addEventListener('trayClickFocusedApp', function (evt) {
alert('Tray Click Focused App (app was already running)');
Ti.API.info('Tray Click Focused App (app was already running)');
});
function loginUser(){
Cloud.Users.login({
login: 'sliang@appcelerator.com',
password: '1234'
}, function (e) {
if (e.success) {
Ti.API.info('Login successful');
subscribeToChannel();
} else {
alert('Error:\n' +
((e.error && e.message) || JSON.stringify(e)));
}
});
}
function subscribeToChannel(){
Cloud.PushNotifications.subscribe({
channel: 'alert',
device_token: deviceToken,
type: Ti.Platform.name == 'android' ? 'android' : 'ios'
}, function (e) {
if (e.success) {
Ti.API.info('Subscribed');
} else {
alert('Error:\n' +
((e.error && e.message) || JSON.stringify(e)));
}
});
}
win.open();
2. Send push notification from dashboard, make sure the push working well.
3. Close the app and remove it from recent.
4. Send push notification again.
5. Click the tray notification to open the app.
Expect Result
callback and trayClickLaunchedApp event should be triggered both.
Actual Result
only trayClickLaunchedApp event triggered, callback event did not get called.
Note
If you only put the app in background, then it works well as expected.
Sample code for classic app:
Tested with code above using 5.3.1.GA with latest ti.cloud 3.2.11 and ti.cloudpush 3.4.1. Not able to reproduce issue. Tested with Android 6.0 Nexus 6. Logs show it works:
[~sliang] Not able to reproduce. It's working correctly for me.
Here's a workaround for it to work:
I believe, what's happening is that the "Callback" event is being called before the App is properly set up. Thus, the
Ti.API.info
comes out fine. But anything that has a UI element, egalert()
won't be called correctly as the App is not ready (timing of the thread). The workaround around above uses a timeout function for 1 second before showing the alert.[~sliang] Is this workaround acceptable? If so, I'll resolve it. Update with more information: It has to do with the Activity being available and getting the context in order to do the alert.
Leaving this ticket open as we should take a look to make sure that this workaround is not needed in the future.
Hey Guys, Any updates on this ticket? We are still facing this issue on some Android devices specifically on Android 7!