【问题标题】:Cannot send push notification via Azure Mobile Service无法通过 Azure 移动服务发送推送通知
【发布时间】:2014-09-29 19:53:57
【问题描述】:

我在 Azure 中设置了一个移动服务并将其连接到我的 Android 应用程序。通过这个应用程序,我调用 Azure API 将对象插入到链接到移动服务的数据库表中。

我已经编写了在插入之前执行的脚本。该脚本旨在向另一台设备发送推送通知。

现在的情况是,对象被插入到表中,但没有收到推送通知。有什么问题?如何调试?

这是我的插入脚本:

function insert(item, user, request) {

    var devices = tables.getTable('Devices');

    var receiverHandle;

    devices.where({userId: item.receiver}).read({
        success: populateHandle
    });

    request.execute({
        success: function() {
            // Write to the response and then send the notification in the background
            request.respond();
            console.log(item);
            push.gcm.send(item.handle, item, {
                success: function(response) {
                    console.log('Push notification sent: ', response);
                }, error: function(error) {
                    console.log('Error sending push notification: ', error);
                }
            });
        }
    });

    function populateHandle(results){
       receiverHandle =  results[0].handle;
    }

}

虽然日志状态推送通知的成功传递。我的设备上没有收到它。

这是其中一个日志:

推送通知发送:{ isSuccessful: true, statusCode: 201, body: '', headers: { 'transfer-encoding': 'chunked', 'content-type': 'application/xml; charset=utf-8', server: 'Microsoft-HTTPAPI/2.0', date: 'Sun, 10 Aug 2014 15:01:52 GMT' }, md5: undefined }

【问题讨论】:

  • 我假设您在 Azure 和 Google 上配置了将消息传递到设备所需的所有 GCM 组件?执行此代码时,您是否在控制台中看到任何错误?
  • 是的,当然我已经配置了 GCM。哪个控制台我可能会看到错误?
  • 在 Azure 管理门户的移动服务中单击“LOGS”选项卡,您将在那里找到条目。
  • 那里没有日志!这是否意味着服务器能够毫无问题地发送推送?
  • 我会在您的代码堆栈中更早地添加更多的 console.log 语句,以找出代码到达的位置。您的 request.execute 语句没有任何错误块。您还需要检查您的代码,因为我不确定它是否会按照您的预期工作。

标签: android node.js azure cloud


【解决方案1】:

参考Migrate a Mobile Service to use Notification Hubs.

Microsoft 已升级移动服务,以推送由通知中心提供支持的通知。如果您在升级之前创建了移动服务,则不会受到影响。

根据响应{ isSuccessful: true, statusCode: 201, body ... },说明你的Mobile Service是新版本。

如果您希望不使用通知中心发送推送,不要使用 push.gcm.send,请改用以下代码 sn-p。

var legacyGcm = require('dpush');
legacyGcm.send(your_GCM_APIKEY, regId, item, function (error, response) {
    if (!error) {
        // success code
    } else {
        // error handling
    }
});

【讨论】:

  • 在使用通知中心时,是否只能将推送发送到标签?我只想将推送发送到特定对象。我怎样才能做到这一点?
猜你喜欢
  • 2013-12-10
  • 1970-01-01
  • 1970-01-01
  • 2016-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多