【问题标题】:Azure mobile service : send push notification to specific android deviceAzure 移动服务:向特定的安卓设备发送推送通知
【发布时间】: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


    【解决方案1】:

    通知中心目前无法发送到特定设备。

    模拟这种情况的机制是通过注册过程和标签。直接使用通知中心 API。注册设备时,请使用适合设备或用户的标签进行注册以进行监听。例如,注册以监听标签 USER-userid 和 DEVICE-deviceid。

    然后,当您要发送到特定设备时,发送到 DEVICE-deviceid,如果您要发送到注册到特定用户的所有设备,您可以发送到 USER-userid;显然,将 userid 和 deviceid 替换为适当的值。

    你可以在这里找到更多关于标签的信息:https://msdn.microsoft.com/library/azure/dn530749.aspx

    【讨论】:

      【解决方案2】:

      如果您想向特定用户发送通知,您必须使用唯一标签或唯一标识符将其注册为 Adrian hall 在之前的回答中描述,我同意他的观点。作为 Android 中的唯一标识符,您可以使用 DeviceId 和 Ios identifierForVendor 它们是独一无二,永不改变。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-24
        • 2013-12-10
        相关资源
        最近更新 更多