Azure 通知中心

Azure notification hub

我有一个使用我的学生 Microsoft 帐户的带有 Azure 通知中心的项目。我启动 Microsoft 免费帐户并创建另一个中心并使用与第一个项目相同的 APNS 认证。现在,当我从 Azure 门户发送测试消息时,我可以收到通知,但当我从我的应用程序发送时,我无法收到任何消息。使用相同的应用只是更改连接字符串和集线器名称?

Using the same app just change the connections string and hub name?

通常情况下,我们不会直接从客户端发送通知。我们通常从服务器后端发送通知。关于如何从后台发送通知可以参考这个article.

如果您仍想通过应用代码发送通知,可以参考此article

在本文中,提供了三种发送通知的方式。

使用 C# 代码,node.js,其余 api。您可以选择一种方式来实现您的要求。

这是 C# 代码演示。

1.Install Microsoft.Azure.NotificationHubs 来自 Nuget 包。

2.Use 下面的代码发送通知。

 private static async void SendNotificationAsync()
 {
     NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("<connection string with full access>", "<hub name>");
     var alert = "{\"aps\":{\"alert\":\"Hello from .NET!\"}}";
     await hub.SendAppleNativeNotificationAsync(alert);
 }

更新:

我建议您可以检查您的连接字符串,确保该连接具有发送通知的权限。

像这样:

然后您可以将此连接添加到代码中并在其中设置正确的通知中心名称。