Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

How to get Notifications when app is stop.

$
0
0

Hi, I am using Push Notifications. When application is runing or in foreground I revice notifications, but when application is stoped I don't get any push notification. Please tell me if there is solution for it.

var DEVICE_TOKEN = null;
 
 var CloudPush = require('ti.cloudpush');
CloudPush.debug = true;
CloudPush.enabled = true;
 
CloudPush.showTrayNotificationsWhenFocused = true;
CloudPush.focusAppOnPush = false;
CloudPush.showTrayNotification = true;
CloudPush.trayClickLaunchedApp = true;
 
 
var Cloud = require('ti.cloud');
Cloud.debug = true;
 
// These events monitor incoming push notifications
 
/*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)');
});
*/
 
CloudPush.addEventListener('callback', function(evt) {
var title = JSON.parse(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)');
 
});
 
function retrieveDeviceToken(){
CloudPush.retrieveDeviceToken({
    success: function deviceTokenSuccess(e) {
        // Use this device token with Ti.Cloud.PushNotifications calls
        // to subscribe and unsubscribe to push notification channels
        //alert('Device Token: ' + e.deviceToken);
 
     DEVICE_TOKEN = e.deviceToken;
 
     //alert(DEVICE_TOKEN);
      loginDefault();
    },
    error: function deviceTokenError(e) {
        alert('Failed to register for push! ' + e.error);
    }
});
 
}
 
function loginDefault(){
    //Create a Default User in Cloud Console, and login
    Cloud.Users.login({
        login: 'testmail@test.com',
        password: 'xxxxxx'
    }, function (e) {
        if (e.success) {
            //alert("login success");
            subscribeToken();
}
else{
    alert("login failed");
}
});
 
}
 
function subscribeToken(){
          Cloud.PushNotifications.subscribeToken({
    device_token: DEVICE_TOKEN,
    channel: 'Sports',
    type: 'android'
}, function (e) {
    if (e.success) {
        alert('Success');
    } else {
        //alert('Error:\n' +((e.error && e.message) || JSON.stringify(e)));
        alert('Error');
    }
});
}
 
 
var win = Ti.UI.createWindow({
    layout: 'vertical',
    backgroundColor: 'white'
});
 
 
retrieveDeviceToken();
win.open();

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>