从钛云推送没有关于android的通知

时间:2018-06-03 08:13:43

标签: android push-notification titanium appcelerator appcelerator-titanium

我没有收到我从appcelerator移动后端服务信息中心发送的通知。我在仪表板中分配了用户和一个频道并发送了推送,但不幸的是,在Android应用程序端无法接收推送。在应用程序方面,我通过以下方式订阅了频道 -

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();

任何人都可以帮助我,我在这里做错了吗?感谢。

1 个答案:

答案 0 :(得分:0)

您的代码似乎正确,但您需要仔细检查一些设置以启用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. 

我希望这些步骤能让您了解推送通知。