我已经在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:”,标头:{'transfer-encoding':'chunked','content-type':'application / xml; charset = utf-8”,服务器:“ Microsoft-HTTPAPI / 2.0”,日期:“ Sun,2014年8月10日15:01:52 GMT”,md5:undefined}

最佳答案

请参阅Migrate a Mobile Service to use Notification Hubs.

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

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

如果您希望发送不带通知中心的推送,请不要使用push.gcm.send,而应使用以下代码片段。



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

07-24 18:47
查看更多