【发布时间】:2015-10-15 10:07:47
【问题描述】:
我正在尝试使用 Azure 移动服务发送推送通知。我让它工作了,但目前它发送到所有使用应用程序密钥的设备。我意识到在 gcm.push.send() 函数中,如果我想将它发送给个人或团体,我必须给出一个标签而不是 null。
我只想将它发送给当前用户。调用插入的用户。我尝试输入用户 gcm 注册 ID,但这不起作用。
我看到了人们注册他们的标签的例子(在 push->edit 脚本中):
exports.register = function (registration, registrationContext, done) {
var userId = registrationContext.user.userId;
registration.tags.push(userId);
done();
};
但是我没有使用身份验证,所以我的 user 变量是未定义的。我得到的只是我的项目表 (item.id) 和注册 ID (item.regid) 中的唯一标识符。 我怎样才能让我的代码工作?这是我的插入:
function insert(item, user, request) {
console.log("Registration ID -> " + item.regid);
var payload = {
"data": {
"message": "notification added"
}
};
request.execute({
success: function() {
// If the insert succeeds, send a notification.
push.gcm.send(item.regid, payload, {
success: function(pushResponse) {
console.log("Sent push:", pushResponse, payload);
request.respond();
},
error: function (pushResponse) {
console.log("Error Sending push:", pushResponse);
request.respond(500, { error: pushResponse });
}
});
},
error: function(err) {
console.log("request.execute error", err)
request.respond();
}
});
}
【问题讨论】:
标签: java android push-notification registration azure-mobile-services