问题描述

在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 中已注册的设备的更多相关文章

  1. 如何删除docker镜像中已配置的volume

    场景: 有个同学不知道因为啥,将容器内部的 /sys/fs/cgroup 挂载到了外面的某个目录: 但是这个目录是很有用的,不想随便被挂载,如何从image中去掉呢? docker没有给出一个方便的方 ...

  2. Azure IoT 技术研究系列4-Azure IoT Hub的配额及缩放级别

    上两篇博文中,我们介绍了将设备注册到Azure IoT Hub,设备到云.云到设备之间的通信: Azure IoT 技术研究系列2-设备注册到Azure IoT Hub Azure IoT 技术研究系 ...

  3. Azure IoT 技术研究系列5-Azure IoT Hub与Event Hub比较

    上篇博文中,我们介绍了Azure IoT Hub的使用配额和缩放级别: Azure IoT 技术研究系列4-Azure IoT Hub的配额及缩放级别 本文中,我们比较一下Azure IoT Hub和 ...

  4. Azure Event Hub 技术研究系列3-Event Hub接收事件

    上篇博文中,我们通过编程的方式介绍了如何将事件消息发送到Azure Event Hub: Azure Event Hub 技术研究系列2-发送事件到Event Hub 本篇文章中,我们继续:从Even ...

  5. Android中使用Notification实现进度通知栏(Notification示例三)

    我们在使用APP的过程中,软件会偶尔提示我们进行版本更新,我们点击确认更新后,会在通知栏显示下载更新进度(已知长度的进度条)以及安装情况(不确定进度条),这就是我们今天要实现的功能.实现效果如下: 在 ...

  6. Android中使用Notification实现普通通知栏(Notification示例一)

    Notification是在你的应用常规界面之外展示的消息.当app让系统发送一个消息的时候,消息首先以图表的形式显示在通知栏.要查看消息的详情需要进入通知抽屉(notificationdrawer) ...

  7. Android开发4: Notification编程基础、Broadcast的使用及其静态注册、动态注册方式

    前言 啦啦啦~(博主每次开篇都要卖个萌,大家是不是都厌倦了呢~) 本篇博文希望帮助大家掌握 Broadcast 编程基础,实现动态注册 Broadcast 和静态注册 Broadcast 的方式以及学 ...

  8. 手动删除portal中托管服务。

    在portal中将server作为托管联合服务器,然后发布了托管服务.若中间取消了托管联合服务器,再重新连接,那么会出现之前的托管服务无法删除的现象. 下文为怎样手动删除这些服务的方法,(不过貌似之后 ...

  9. 用于svn添加当前目录下所有未追踪的文件,和删除所有手动删除的文件的脚本

    由于要经常用到类似与 git 中的 git add --all 这种操作,但是发现svn中并不支持类似的操作. 虽然可以使用 wildcard 进行匹配,但是 wildcard是在shell中进行匹配 ...

  10. Azure Automation (2) 定期删除存储账号中的文件

    <Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的Azure China. 本文是对笔者之前的文档Azure Backup (1) 将SQL ...

随机推荐

  1. Couldn't launch Python exit code 9009

    Couldn't launch Python exit code 9009 start stable-diffusion-webui,发现,python 环境没有,我本地其实是已经安装完毕的,后来发现 ...

  2. 深入浅出Java多线程(一):进程与线程

    引言 大家好,我是你们的老伙计秀才. 在计算机系统的发展历程中,早期的计算机操作模式十分单一和低效.用户只能逐条输入指令,而计算机则按照接收指令的顺序逐一执行,一旦用户停止输入或进行思考,计算机会处于 ...

  3. 深度学习基础入门篇[六]:模型调优,学习率设置(Warm Up、loss自适应衰减等),batch size调优技巧,基于方差放缩初始化方法。

    深度学习基础入门篇[六]:模型调优,学习率设置(Warm Up.loss自适应衰减等),batch size调优技巧,基于方差放缩初始化方法. 1.学习率 学习率是训练神经网络的重要超参数之一,它代表 ...

  4. C++ STL 标准模板库(容器总结)算法

    C++ 标准模板库STL,是一个使用模板技术实现的通用程序库,该库由容器container,算法algorithm,迭代器iterator,容器和算法之间通过迭代器进行无缝连接,其中所包含的数据结构都 ...

  5. DAPR-分布式系统运行时简介

    Dapr全称Distributed Application Runtime,翻译过来就是分布式应用程序运行时,在v1.0发布后得到了极大的发展.本章将向你介绍Dapr架构的核心概念,为您使用Dapr进 ...

  6. Mybatis(一对一、一对多、多对多)操作

    * 首先列出示例中用到的数据库表 user表: accout表: role表: user_role表: 建表语句如下: DROP TABLE IF EXISTS `user`; CREATE TABL ...

  7. ROS节点通信(一)消息发布和订阅

    目录 1.说明 2.创建工作空间 3.创建功能包 4.编写自定义传输类型文件 5.编写源代码 5.1.编写发布者代码 5.2.编写订阅者代码 6.编译 7.启动运行 8.查看ROS网络结构图 1.说明 ...

  8. 【链表】链表OJ-力扣2074. 反转偶数长度组的节点【超详细的算法解释】

    说在前面 今天博主给大家带来的是力扣上的一道链表OJ,完成这道题后,博主感觉这题覆盖了很多链表的解题思想,另外,这道题对指针的控制也是比较高的.在这里博主将这道好题分享给大家! 另外,对于链表等数据结 ...

  9. 内存泄漏定位工具之 mtrace(一)

    1 前言 mtrace(memory trace),是 GNU Glibc 自带的内存问题检测工具,它可以用来协助定位内存泄露问题.它的实现源码在glibc源码的malloc目录下,其基本设计原理为设 ...

  10. 手把手带你上手swagger3

    配置POM 只需要加一个依赖,并且要注意,swagger3在springboot2.5版本以上会出现问题 <dependency> <groupId>io.springfox& ...