问题描述

在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. [转帖]RFC1180

    [译] RFC 1180:朴素 TCP/IP 教程(1991) 译者序 本文翻译自 1991 年的一份 RFC(1180): A TCP/IP Tutorial. 本文虽距今将近 20 年,但内容并未 ...

  2. UOS 以及 部分NetworkManager管理linux服务器 设置固定IP地址的办法.

    UOS 以及 部分NetworkManager管理linux服务器 设置固定IP地址的办法. 很多操作系统没法右键 网络连接进行处理 但是发现大部分机器都增加了 NetworkManager 的网络管 ...

  3. kettle系统列文章02---如何建立一个转换

    1.连接mysql 主对象树---->DB连接---->新建 2.连接sqlserver 主对象树--->DB连接----->新建 3.设置数据库为共享:在db上右键---&g ...

  4. 【scikit-learn基础】--『回归模型评估』之准确率分析

    分类模型的评估和回归模型的评估侧重点不一样,回归模型一般针对连续型的数据,而分类模型一般针对的是离散的数据. 所以,评估分类模型时,评估指标与回归模型也很不一样,比如,分类模型的评估指标通常包括准确率 ...

  5. TienChin 渠道管理-渠道类型

    在上一篇文章当中,表里面有一个渠道类型,我们这节主要是将这个渠道类型创建好,首先我们来看看字典表. sys_dict_type 表: 字段名 数据类型 注释 dict_id bigint 字典主键 d ...

  6. 在K8S中,deploy升级过程包括什么?

    在Kubernetes (K8S) 中,Deployment的升级过程主要包括以下几个步骤: 更新Deployment配置: 当需要对应用程序进行升级时,通常会更新Deployment的YAML配置文 ...

  7. Windows XP Professional with Service Pack 3 (x86)

    Windows XP Professional with Service Pack 3 (x86) 链接:https://pan.baidu.com/s/1p99vLx5psoq9K4ONlRpkZA ...

  8. Markdown Rules 详解

    使用VSCode编写Markdown文件时,建议安装插件markdownlint,它可以帮助自己更加规范的写文章. 下面是所有的markdown语法错误信息以便纠错. Rules文档 Markdown ...

  9. C++对象之谜(封装篇)

    这篇博客简要记录下C++对象的相关内容,以便回顾时使用. C++类的定义 我们使用C++定义一个矩形(Rectangle)类,它的基本属性有:长(width),宽(width), 对矩形的基本操作有: ...

  10. 目录:CH57x/CH58x/CH59x/CH32V208低功耗蓝牙应用

    外设相关: CH59x 系统16位PWM使用 - 小舟从此逝_1 - 博客园 (cnblogs.com) CH59X/CH58X/CH57X PWM使用 - 小舟从此逝_1 - 博客园 (cnblog ...