【问题标题】:titanium studio push notifications closing the app关闭应用程序的钛工作室推送通知
【发布时间】:2014-04-15 11:59:56
【问题描述】:

我正在尝试在由钛工作室开发的 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)');
}); 

我做错了什么,任何人都会建议我,如何解决这个问题

提前感谢

【问题讨论】:

  • 你是在单独的 js 文件中运行它吗?
  • 以上所有代码仅在app.js中

标签: android notifications titanium titanium-mobile


【解决方案1】:

尝试如下更改您的代码

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)

【讨论】:

  • 您好 Anand,感谢您的回复,我修改为 ti.cloudpush 然后我收到此错误 Requested module not找到:ti.module.js 中的 ti.cloudpush
  • Anand,很抱歉问了你这么多次,但我是开发甚至移动应用程序的新手,我需要的是接收来自 c#.net 的推送通知,对于安卓应用。我已经创建了 C2DM 并且我能够通过上面的代码获取设备令牌,我得到 不幸的是应用程序已关闭此错误请指导我如何做到这一点,是否必须进行 ACS 注册?
  • 我不明白你在做什么:(。请在命令提示符下使用adb logcat命令检查设备日志。你可以在接收推送时看到错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-01-06
  • 1970-01-01
  • 2012-02-27
  • 2022-01-13
  • 2021-03-08
  • 1970-01-01
  • 2019-09-26
相关资源
最近更新 更多