我在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,正文:'',标题:{' transfer-encoding':' chunked', ' content-type':' application / xml; charset = utf-8',服务器:' Microsoft-HTTPAPI / 2.0',日期:' Sun,2014年8月10日15:01:52 GMT' },md5:undefined}
答案 0 :(得分:0)
请参阅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
}
});