gpt4 book ai didi

javascript - 使用 ACS 的推送通知不起作用

转载 作者:行者123 更新时间:2023-11-30 06:38:06 26 4
gpt4 key购买 nike

您好,我正在使用 ACS 实现推送通知。当我单击“注册推送通知”按钮时,出现以下错误。注册推送失败! com.appcelerator.cloud.push.PushServiceException:无效的 token 请求。消息:找不到正确的 Android 配置,请提供有效的 token

Titanium.UI.setBackgroundColor('#000');

var win = Ti.UI.createWindow({
backgroundColor:'#ccc',
title:'Android Cloud Push Notification'
})


var CloudPush = require('ti.cloudpush');
CloudPush.debug = true;
CloudPush.enabled = true;
CloudPush.showTrayNotificationsWhenFocused = true;
CloudPush.focusAppOnPush = false;

var deviceToken;

var Cloud = require('ti.cloud');
Cloud.debug = true;


var submit = Ti.UI.createButton({
title : 'Register For Push Notification',
color:'#000',
height : 53,
width : 200,
top : 100,
});

win.add(submit);

submit.addEventListener('click', function(e) {
CloudPush.retrieveDeviceToken({
success: function deviceTokenSuccess(e) {
alert('Device Token: ' + e.deviceToken);
deviceToken = e.deviceToken
loginDefault();
},
error: function deviceTokenError(e) {
alert('Failed to register for push! ' + e.error);
}
});
});


function loginDefault(e){
//Create a Default User in Cloud Console, and login
Cloud.Users.login({
login: 'push123',
password: 'push123'
}, function (e) {
if (e.success) {
alert("login success");
defaultSubscribe();
} else {
alert('Error: ' +((e.error && e.message) || JSON.stringify(e)));
}
});
}

function defaultSubscribe(){
Cloud.PushNotifications.subscribe({
channel: 'alert',
device_token: deviceToken,
type: 'android'
}, function (e){
if (e.success) {
alert('Subscribed for Push Notification!');
}else{
alert('Error:' +((e.error && e.message) || JSON.stringify(e)));
}
});
}

CloudPush.addEventListener('callback', function (evt) {
//alert(evt);
//alert(evt.payload);
);

CloudPush.addEventListener('trayClickLaunchedApp', function (evt) {
Ti.API.info('Tray Click Launched App (app was not running)');
//alert('Tray Click Launched App (app was not running');
});

CloudPush.addEventListener('trayClickFocusedApp', function (evt) {
Ti.API.info('Tray Click Focused App (app was already running)');
//alert('Tray Click Focused App (app was already running)');
});

win.open();

最佳答案

尝试以下链接

http://www.titaniumtutorial.com/2012/06/appcelerator-cloud-push-notification-in.html?m=1

如果它没有解决您的问题并且您正在使用 wifi,请将其从 wifi 更改并在 3G 或 GPRS 中尝试,注册推送 wifi 时出现问题

关于javascript - 使用 ACS 的推送通知不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13326696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com