android - 无法通过 Azure 移动服务发送推送通知

标签 android node.js azure cloud

我已在 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', 服务器: 'Microsoft-HTTPAPI/2.0', 日期: 'Sun, 2014 年 8 月 10 日 15:01:52 GMT' }, md5: 未定义 }

最佳答案

引用Migrate a Mobile Service to use Notification Hubs.

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

根据响应 { isSuccessful: true, statusCode: 201, body ... },表明您的移动服务是新版本。

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

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

关于android - 无法通过 Azure 移动服务发送推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25112499/

相关文章:

Azure B2C 无效 Jwt 签名

android - 添加电视应用推荐支持库

android - 如何将 Matlab 代码库与 Android 集成?

android - 如何使用模糊库获取直接位图结果

android - 如何操作APK变体版本代码

Node.js + 懒惰 : Iterate file lines

node.js - 不将图像保存在 PDF 中,在 Node/expressJs 中出现错误

javascript - 为什么在新 Node 版本中使用字母数字键创建对象如此缓慢?

azure - 将 DotNetOpenAuth OAuth 2 与 Azure 结合使用 - 读取证书 - 提取 key 时遇到困难

azure - 指示 Azure Function App 仅接受 Application/json