Android Tianium studio推送通知关闭应用程序

Android Tianium studio推送通知关闭应用程序,android,notifications,titanium,titanium-mobile,Android,Notifications,Titanium,Titanium Mobile,我正试图在Tianium studio开发的android应用程序中显示推送通知,我的警报不幸关闭了,在这之后,我的代码被关闭了 try { CloudPush.retrieveDeviceToken({ success : function deviceTokenSuccess(e) { deviceID = e.deviceToken; Ti.API.info(deviceID); Ti.App

我正试图在Tianium studio开发的android应用程序中显示推送通知,我的警报不幸关闭了,在这之后,我的代码被关闭了

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)');
}); 
我做错了什么?有人会建议我怎么解决这个问题吗


感谢advace

尝试按如下方式更改代码

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)');
}); 
我已经从代码中删除了回调方法。
另外,请确保您使用的是最新的CloudPush模块。请检查TiApp.xml,如果您选择“*”作为模块版本,请将其更改为最新版本(我是3.2.3)

您是否在单独的js文件中运行它?以上所有代码都在app.js onlyHello Anand中,谢谢您的回复,我像ti.cloudpush一样进行了修改,然后我收到了一个错误请求模块未找到:ti.cloudpush位于ti.module.jsAnand,很抱歉问了你这么多次,但我对开发甚至移动应用程序都是新手,我需要的是我收到c#net针对android应用程序的推送通知。我已经创建了C2DM,我可以通过上面的代码获得设备令牌,不幸的是,应用程序已关闭。此错误请指导我如何操作,ACS注册是否必须?我不明白你在做什么:(.请使用命令提示符中的
adb logcat
命令检查设备日志。您可以在接收推送时看到错误