【Azure Notification Hub】如何手动删除 Notification Hub 中已注册的设备
问题描述
在Notification Hub中注册了设备后,从Azure门户上没有找到相应的入口来删除已注册设备 (Active Devices)

如果使用C# SDK是否有办法删除呢?
问题解答
可以的,查看Notification Hub的文档,可以通过注册ID来删除一个注册设备:https://docs.azure.cn/zh-cn/notification-hubs/notification-hubs-push-notification-registration-management#example-code-to-register-with-a-notification-hub-from-a-backend-using-a-registration-id

示例代码
MainPage.xaml.cs
using Microsoft.Azure.NotificationHubs;
using Microsoft.WindowsAzure.Messaging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Networking.PushNotifications;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 namespace NoteHubApp
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
//Connection String & Notification Hub Name
const string nhName = "NH Name";
const string managementConnectionString = "NH Connection String"; NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(managementConnectionString, nhName); List<string> registrationIds = new List<string>();
public MainPage()
{
this.InitializeComponent();
} private void MyButton_Click(object sender, RoutedEventArgs e)
{
RegisterDevices(); RefreshAllRegistration();
}
private async void RegisterDevices()
{
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
// create a registration description object of the correct type, e.g.
var reg = new WindowsRegistrationDescription(channel.Uri);
// Create
var result = await hub.CreateRegistrationAsync(reg);
// Displays the registration ID so you know it was successful
if (result.RegistrationId != null)
{
registrationIds.Add(result.RegistrationId); var dialog = new MessageDialog("Registration successful: " + result.RegistrationId);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
}
private void Refresh_Click(object sender, RoutedEventArgs e)
{
RefreshAllRegistration();
} private async void RefreshAllRegistration()
{
registrationIds.Clear(); var allRegistrations = await hub.GetAllRegistrationsAsync(100); showresult.Text = "Registrations Total is " + allRegistrations.Count().ToString() + "\n"; foreach (var registration in allRegistrations)
{
registrationIds.Add(registration.RegistrationId); showresult.Text += registration.RegistrationId + "\n";
} //var dialogs = new MessageDialog("Get Registrations Number " + allRegistrations.Count().ToString());
//dialogs.Commands.Add(new UICommand("OK"));
//await dialogs.ShowAsync();
} private void Delete_Click(object sender, RoutedEventArgs e)
{
DeleteDevices();
} private async void DeleteDevices()
{
if (registrationIds.Count > 0)
{
var rid = registrationIds[registrationIds.Count - 1];
// Get by ID
var r = await hub.GetRegistrationAsync<RegistrationDescription>(rid);
try
{
// delete
await hub.DeleteRegistrationAsync(r);
registrationIds.Remove(rid);
var dialog = new MessageDialog("Delete Registration: " + rid);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
catch
{
} RefreshAllRegistration();
}
}
}
}
MainPage.xaml
<Page
x:Class="NoteHubApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:NoteHubApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Height="1027" Width="1623">
<Grid Margin="0,0,66,30">
<Button x:Name="MyButton" Content="Register One!" Click="MyButton_Click" Height="244" Width="243" Margin="48,610,0,0" VerticalAlignment="Top" RenderTransformOrigin="2.758,-2.919" Background="#33228919"/>
<Button x:Name="MyButton_Copy" Content="Refresh All Register!" Click="Refresh_Click" Height="809" Width="198" Margin="723,36,0,0" VerticalAlignment="Top" Background="#33D26136"/>
<Button x:Name="MyButton_Copy1" Content="Delete Old One!" Click="Delete_Click" Height="238" Width="374" Margin="315,613,0,0" VerticalAlignment="Top" Background="#33172D5D"/>
<TextBox x:Name="showresult" HorizontalAlignment="Left" Margin="30,28,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Height="556" Width="664" Background="#667B857A"/>
</Grid>
</Page>
UI 展示如下:

参考资料
注册管理 (DeleteRegistrationAsync) : https://docs.azure.cn/zh-cn/notification-hubs/notification-hubs-push-notification-registration-management#example-code-to-register-with-a-notification-hub-from-a-backend-using-a-registration-id
【Azure Notification Hub】如何手动删除 Notification Hub 中已注册的设备的更多相关文章
- 如何删除docker镜像中已配置的volume
场景: 有个同学不知道因为啥,将容器内部的 /sys/fs/cgroup 挂载到了外面的某个目录: 但是这个目录是很有用的,不想随便被挂载,如何从image中去掉呢? docker没有给出一个方便的方 ...
- Azure IoT 技术研究系列4-Azure IoT Hub的配额及缩放级别
上两篇博文中,我们介绍了将设备注册到Azure IoT Hub,设备到云.云到设备之间的通信: Azure IoT 技术研究系列2-设备注册到Azure IoT Hub Azure IoT 技术研究系 ...
- Azure IoT 技术研究系列5-Azure IoT Hub与Event Hub比较
上篇博文中,我们介绍了Azure IoT Hub的使用配额和缩放级别: Azure IoT 技术研究系列4-Azure IoT Hub的配额及缩放级别 本文中,我们比较一下Azure IoT Hub和 ...
- Azure Event Hub 技术研究系列3-Event Hub接收事件
上篇博文中,我们通过编程的方式介绍了如何将事件消息发送到Azure Event Hub: Azure Event Hub 技术研究系列2-发送事件到Event Hub 本篇文章中,我们继续:从Even ...
- Android中使用Notification实现进度通知栏(Notification示例三)
我们在使用APP的过程中,软件会偶尔提示我们进行版本更新,我们点击确认更新后,会在通知栏显示下载更新进度(已知长度的进度条)以及安装情况(不确定进度条),这就是我们今天要实现的功能.实现效果如下: 在 ...
- Android中使用Notification实现普通通知栏(Notification示例一)
Notification是在你的应用常规界面之外展示的消息.当app让系统发送一个消息的时候,消息首先以图表的形式显示在通知栏.要查看消息的详情需要进入通知抽屉(notificationdrawer) ...
- Android开发4: Notification编程基础、Broadcast的使用及其静态注册、动态注册方式
前言 啦啦啦~(博主每次开篇都要卖个萌,大家是不是都厌倦了呢~) 本篇博文希望帮助大家掌握 Broadcast 编程基础,实现动态注册 Broadcast 和静态注册 Broadcast 的方式以及学 ...
- 手动删除portal中托管服务。
在portal中将server作为托管联合服务器,然后发布了托管服务.若中间取消了托管联合服务器,再重新连接,那么会出现之前的托管服务无法删除的现象. 下文为怎样手动删除这些服务的方法,(不过貌似之后 ...
- 用于svn添加当前目录下所有未追踪的文件,和删除所有手动删除的文件的脚本
由于要经常用到类似与 git 中的 git add --all 这种操作,但是发现svn中并不支持类似的操作. 虽然可以使用 wildcard 进行匹配,但是 wildcard是在shell中进行匹配 ...
- Azure Automation (2) 定期删除存储账号中的文件
<Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的Azure China. 本文是对笔者之前的文档Azure Backup (1) 将SQL ...
随机推荐
- 《Javascript高级程序设计》读书笔记——继承与原型链
继承与原型链 原型链 在原型那一节中,讲到了用于搜索对象属性的原型搜索机制:而原型链,本质上 就是对原型搜索机制的扩充: 回想下之前的内容,我们要读取一个Person的实例p属性,会先搜索实例p:如果 ...
- 【如何提高IT运维效率】深度解读京东云基于NLP的运维日志异常检测AIOps落地实践
作者:京东科技 张宪波.张静.李东江 基于NLP技术对运维日志聚类,从日志角度快速发现线上业务问题 日志在IT行业中被广泛使用,日志的异常检测对于识别系统的运行状态至关重要.解决这一问题的传统方法需 ...
- 获取Visual Studio所用MSVC编译器版本:_MSC_VER数值
本文介绍查看Visual Studio软件_MSC_VER值的方法. _MSC_VER是微软公司推出的C/C++编译器--MSVC编译器的一个内置宏,其值表示当前Visual Studio软件 ...
- 一键式文本纠错工具,整合了BERT、ERNIE等多种模型,让您立即享受纠错的便利和效果
pycorrector一键式文本纠错工具,整合了BERT.MacBERT.ELECTRA.ERNIE等多种模型,让您立即享受纠错的便利和效果 pycorrector: 中文文本纠错工具.支持中文音似. ...
- C/C++ 操作注册表与服务
枚举注册表启动项: 通过添加注册表启动项,可以很方便地完成自启动,常用的启动位置有CurrentVersion,BootExecute,Active Setup. #include <stdio ...
- Win32汇编:算数运算指令总结
整理复习汇编语言的知识点,以前在学习<Intel汇编语言程序设计 - 第五版>时没有很认真的整理笔记,主要因为当时是以学习理解为目的没有整理的很详细,这次是我第三次阅读此书,每一次阅读都会 ...
- 记录一则因主机名讹误导致的RAC启动异常
1.故障现象 2.解决方案 环境:RHEL 7 + Oracle 19.5 RAC 1.故障现象 最近遇到客户的一套19c测试环境,在一次主机重启后发现集群无法启动,使用crsctl stat res ...
- Redis Desktop Manager 0.9.3.817 最后一版免费版,新版要收费
链接: https://pan.baidu.com/s/1wyELUhOn_rumFecNAS7L0A 提取码: 1631 版本是两三个月前,我从官网下载的,然后顺便存到了我的移动硬盘上.0 ...
- JS leetcode 删除排序数组中的重复项 题解分析
壹 ❀ 引 一日一题,今天的题目来自于leetcode26. 删除排序数组中的重复项,其实在之前我们已经做了一道类似的题目,可参考JS leetcode 移除元素 题解分析,关于本题描述如下: 给定一 ...
- NC20259 [SCOI2007]降雨量
题目链接 题目 题目描述 我们常常会说这样的话:"X年是自Y年以来降雨量最多的".它的含义是X年的降雨量不超过Y年,且对于任意 Y<Z<X,Z年的降雨量严格小于X年. ...