gpt4 book ai didi

c# - 推送通知不使用 Azure 从控制台发送

转载 作者:行者123 更新时间:2023-12-03 03:10:01 24 4
gpt4 key购买 nike

我使用 this guide 创建了一个通知中心和 these instructions (了解如何将 Firebase 添加到 Azure)。

当我在 Azure 上使用“测试发送”进行发送时,推送通知已成功发送。但是,当我使用前面提到的指南中的控制台示例发送它时,使用 SendGcmNativeNotificationAsync 方法时它会崩溃。
可能出了什么问题?

我的命名空间包含字母和 -,但我的集线器名称也包含 _。这可能是问题所在(如果是,为什么他们在创建过程中没有告诉我)?

编辑:修改后的代码

var connectionStr = ServiceBusConnectionStringBuilder.CreateUsingSharedAccessKey(new Uri({uri}), "DefaultSendSharedAccessSignature", "Ln4em6ZqeukRS3y1Hgq/3m5V2S51IBIkG7tk+MAfO/Y=");

var hub = NotificationHubClient.CreateClientFromConnectionString(connectionStr, {hub-name});

await hub.SendGcmNativeNotificationAsync("{ \"data\" : {\"message\":\"Hello from Azure!\"}}");

Console.ReadLine();

最佳答案

尝试这样的事情:

private static async void SendNotificationAsync()  
{
NotificationHubClient hub = NotificationHubClient
.CreateClientFromConnectionString("<connection string with full access>", "<hub name>");
var notif = "{ \"data\" : {\"message\":\"" + "Hola" + "\"}}";
await hub.SendGcmNativeNotificationAsync(notif);
}

获取自:http://www.c-sharpcorner.com/blogs/sending-notification-from-a-console-application-using-notification-hubs

连接字符串可以在您的通知中心(访问策略)中找到: enter image description here

它对我来说适用于简单的控制台应用程序测试。

关于c# - 推送通知不使用 Azure 从控制台发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39745507/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com