azure - 删除 Azure 通知中心中的注册

标签 azure azure-mobile-services azure-notificationhub

对于我的环境,我使用 Rest API 通过通知中心注册/取消注册我的设备。

每当我的用户登录时,我的应用程序都会向 GCM 注册,获取注册 ID,然后向通知中心注册以接收通知。这工作没有任何问题。

当我的用户注销时,我的应用程序希望从通知中心删除该注册,以便用户将不再收到任何通知。

查阅此页面了解如何删除注册后

https://msdn.microsoft.com/en-us/library/azure/dn223268.aspx

我编写了以下代码:

var client = new XMLHttpRequest();
client.onload = function () {
    if (client.readyState == 4) {
        if (client.status == 200) {
            // we are logged out
            console.log("(sendNHDeleteRegistrationRequest) NH delete registration is successful");
            chrome.storage.local.set({registered: false});
            updateRegisterUI();
        } else {
            console.log("(sendNHDeleteRegistrationRequest) NH delete registration is not successful");
            console.log("(sendNHDeleteRegistrationRequest) HTTP Status: " + client.status + " : " + client.statusText);
            console.log("(sendNHDeleteRegistrationRequest) HTTP Response: " + "\n" + client.responseText);
        }
    }
};

var url = gOriginalUri + "/registrations/" + gRegistrationId + "?api-version=2015-01";
    client.open("POST", url, true);
    client.setRequestHeader("Content-Type", "application/atom+xml;type=entry;charset=utf-8");
    client.setRequestHeader("Authorization", gSasToken);
    client.setRequestHeader("x-ms-version", "2015-01");

try {
    client.send();
    chrome.storage.local.set({registered: false});
    updateRegisterUI();
}
catch(err) {
    console.log(err.message);
}

但我总是收到此错误:

(sendNHDeleteRegistrationRequest) NH删除注册不成功 register.js:230(sendNHDeleteRegistrationRequest)HTTP 状态:405:不允许方法 register.js:231(sendNHDeleteRegistrationRequest)HTTP 响应: 405指定的 HTTP 谓词 (POST) 无效。.TrackingId:64cd952b-ffda-42f8-860b-22dd4aa397ea_G3,TimeStamp:7/31/2015 4:00:48 AM

所以我的问题是 1. 要在用户注销时停止接收我的应用程序的通知,标准做法是什么?阻止在应用程序中触发通知或从通知中心删除注册? 2. 我是否以正确的方式使用此删除注册?为什么我收到 405 Method not allowed?

谢谢!

最佳答案

我看到您正在使用 POST 方法来删​​除注册。您不应该使用 DELETE 来代替吗?

var url = gOriginalUri + "/registrations/" + gRegistrationId + "?api-version=2015-01";
client.open("POST", url, true);
client.setRequestHeader("Content-Type", "application/atom+xml;type=entry;charset=utf-8");
client.setRequestHeader("Authorization", gSasToken);
client.setRequestHeader("x-ms-version", "2015-01");

尝试:

client.open("DELETE", url, true);

关于azure - 删除 Azure 通知中心中的注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31737898/

相关文章:

azure - 通过 IP 地址阻止对 url 的访问

azure - 授予对新主机的访问权限?

Azure 通知中心 : Count is not updated in Active Device limit count after delete registration from backend

ios - 为什么我不能将属性的值设置为 readWithCompletion 完成 block 的 items 参数?

ios - Azure ios应用程序身份验证错误

ios - Azure 通知中心向特定设备发送通知

Azure Hub 通知无法发送到 FCM

azure - 辅助角色中的 ServicePointManager.DefaultConnectionLimit

azure - Azure 的最佳配置管理软件

node.js - Azure 移动服务导出模块和表对象