[英]Getting no notification on android from titanium cloud push
I'm not getting the notification that i'm sending from the appcelerator mobile backend services dashboard. 我没有收到从appcelerator移动后端服务仪表板发送的通知。 I assigned users and a channel in the dashboard and sent the push, but unfortunately that push couldn't receive in the android app side.
我在仪表板上分配了一个用户和一个通道并发送了推送,但不幸的是,该推送在Android应用程序端无法接收。 In the app side, I subscribed the channel by following -
在应用程序方面,我通过以下方式订阅了频道-
var CloudPush = require('ti.cloudpush');
var deviceToken = null;
// Initialize the module
CloudPush.retrieveDeviceToken({
success : deviceTokenSuccess,
error : deviceTokenError
});
// Enable push notifications for this device
// Save the device token for subsequent API calls
function deviceTokenSuccess(e) {
deviceToken = e.deviceToken;
subscribeToChannel();
}
function deviceTokenError(e) {
Ti.API.info('Failed to register for push notifications! ' + e.error);
alert('Failed to register for push notifications! ' + e.error);
}
// Process incoming push notifications
CloudPush.addEventListener('callback', function(evt) {
alert("Notification received: " + evt.payload);
});
var Cloud = require("ti.cloud");
function loginUser() {
// Log in to Arrow
Cloud.Users.login({
login : 'nuibb',
password : '123456'
}, function(e) {
if (e.success) {
alert('Login successful');
} else {
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
}
function subscribeToChannel() {
Ti.API.info('Token : ' + deviceToken);
// Subscribe the user and device to the 'test' channel
// Specify the push type as either 'android' for Android or 'ios' for iOS
// Check if logged in:
Cloud.PushNotifications.subscribe({
channel : 'test',
device_token : deviceToken,
type : Ti.Platform.name == 'android' ? 'android' : 'ios'
}, function(e) {
if (e.success) {
alert('Subscribed');
} else {
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
}
function unsubscribeToChannel() {
// Unsubscribes the user and device from the 'test' channel
Cloud.PushNotifications.unsubscribe({
channel : 'test',
device_token : deviceToken
}, function(e) {
if (e.success) {
alert('Unsubscribed');
} else {
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
}
loginUser();
Can anyone help me please what I'm doing wrong here? 有人可以帮我请我在这里做错什么吗? Thanks.
谢谢。
Your code seems correct but you need to double-check some settings to enable Push: 您的代码似乎正确,但是您需要仔细检查一些设置以启用Push:
1- Turn off the LiveView always when you are testing Push Notifications.
2- Cloud services are enabled in your project.
3- Server key & Sender ID is correctly setup on your Appcelerator Project dashboard.
4- You are able to retrieve device tokens properly.
5- You are able to subscribe to channels properly.
I hope these steps will get you up on Push Notifications. 我希望这些步骤能使您了解推送通知。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.