我已在 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/