钛工作室推送通知关闭的应用程序 [英] titanium studio push notifications closing the app

查看:259
本文介绍了钛工作室推送通知关闭的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,以显示Android应用程序推送通知,钛工作室开发的,我与得到警报的不幸的是应用程序是在此之后我被clossing关闭后,我的code是

I am trying to show push notifications in android app, developed by titanium studio, my getting alert with unfortunately app is closed after this my is clossing, my code is

try {

    CloudPush.retrieveDeviceToken({
        success : function deviceTokenSuccess(e) {
            deviceID = e.deviceToken;
            Ti.API.info(deviceID);
            Ti.App.Properties.setString('deviceid', '' + deviceID);
        },
        error : function deviceTokenError(e) {
            alert('Failed to register for push! ' + e.error);
        }
    });

} catch(e) {
    alert('Error :', e);
}

// Enable push notifications for this device
// Save the device token for subsequent API calls
function deviceTokenSuccess(e) {
    CloudPush.enabled = true;
    deviceToken = e.deviceToken;
}

function deviceTokenError(e) {
    alert('Failed to register for push notifications! ' + e.error);
}


// Process incoming push notifications
CloudPush.addEventListener('callback', function(evt) {
    //alert(evt.payload);
    var alertNotification = Titanium.UI.createAlertDialog({
                title : 'app',
                message : evt.data.alert,
                cancel : 1,
                buttonNames : ['OK']
            });
            alertNotification.show();

});
// Triggered when the push notifications is in the tray when the app is not running
CloudPush.addEventListener('trayClickLaunchedApp', function(evt) {
    Ti.API.info('Tray Click Launched App (app was not running)');
});
// Triggered when the push notifications is in the tray when the app is running
CloudPush.addEventListener('trayClickFocusedApp', function(evt) {
    Ti.API.info('Tray Click Focused App (app was already running)');
}); 

什么我做了错误的将任何一个建议我,如何解决这个isssue

what was the wrong I am doing will any one suggest me, how to resolve this isssue

感谢advace

推荐答案

试着改变你的code如下:

Try changing your code as follows

var CloudPush = require('ti.cloudpush');
try {

    CloudPush.retrieveDeviceToken({
        success : function deviceTokenSuccess(e) {
            deviceID = e.deviceToken;
            CloudPush.enabled = true;
            Ti.API.info(deviceID);
            Ti.App.Properties.setString('deviceid', '' + deviceID);
        },
        error : function deviceTokenError(e) {
            alert('Failed to register for push! ' + e.error);
        }
    });

} catch(e) {
    alert('Error :' + e);
}

// Process incoming push notifications
CloudPush.addEventListener('callback', function(evt) {
    //alert(evt.payload);
    var alertNotification = Titanium.UI.createAlertDialog({
                title : 'app',
                message : evt.data.alert,
                cancel : 1,
                buttonNames : ['OK']
            });
            alertNotification.show();

});
// Triggered when the push notifications is in the tray when the app is not running
CloudPush.addEventListener('trayClickLaunchedApp', function(evt) {
    Ti.API.info('Tray Click Launched App (app was not running)');
});
// Triggered when the push notifications is in the tray when the app is running
CloudPush.addEventListener('trayClickFocusedApp', function(evt) {
    Ti.API.info('Tray Click Focused App (app was already running)');
}); 

我已删除从code中的回调方法。
还请确保您正在使用最新CloudPush模块。请检查TiApp.xml,如果你选择*为模块版本,将其更改为最新数字(3.2.3对我来说)

I have removed the callback methods from your code. And also please make sure that you're using the latest CloudPush module. Please check the TiApp.xml, if you have selected '*' as module version, change it to latest number (3.2.3 for me)

这篇关于钛工作室推送通知关闭的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆