【问题标题】:Notifications not received on Android device via Azure Notifications hub, but on firebase console they deliver as expectedAndroid 设备上未通过 Azure 通知中心收到通知,但在 firebase 控制台上它们按预期交付
【发布时间】:2022-01-25 21:41:44
【问题描述】:

我最近更新了我的应用程序以实现跨平台可用性,但我无法接收推送通知。

当我向后端发送“警报”时,应该通知用户有人发出了警报。

现在当我调用 SendFCMNativeNotificationsAsync 方法时,我总是得到排队响应(当我只有一个 Android 版本时,他们总是说成功)。

private async Task sendNotifAsync(Alert alert)
{
    Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null;
    HttpStatusCode ret = HttpStatusCode.InternalServerError;

    var cafe = cafeRepository.GetById(alert.CafeId);
    var message = alert.UserName + " needs help in " + cafe.Name;
    var notif = "{ \"notification\":{\"title\":\"Somebody needs help\",\"body\":\""+message+"\"},\"data\" : {\"message\":\"" + "From " + alert.UserName + ": " + message + "\"}}";
    outcome = await Notifications.Instance.Hub.SendFcmNativeNotificationAsync(notif);
}

这是我用来在后端调用notificationhub 的代码。

奇怪的是,当我尝试通过 firebase 控制台发送测试通知时,它按预期工作,所以我真的不知道现在去哪里解决这个问题。

【问题讨论】:

    标签: flutter asp.net-core push-notification firebase-cloud-messaging azure-notificationhub


    【解决方案1】:

    要将推送通知发送到针对 AndroidiOS 的 Flutter 应用程序,首先我们需要使用最新版本为客户端处理 设备注册以及使用 ASP.NET Core Web API 后端的最佳安装方法。查看此Registration management 文档以获取更多详细信息。

    您遇到此问题的原因可能有很多,可能是由于通知中心配置错误,也可能是由于注册无效和 应用程序问题 >推送通知服务也可能是问题所在。

    由于您从 firebase 控制台收到通知,因此推送通知服务应该不是问题。您仍然可以在初始化NotificationHubClient 时使用EnableTestSend 属性来获取有关在发送通知时发生的推送通知服务错误的详细状态。

    bool enableTestSend = true;
    NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(connString, hubName, enableTestSend);
    
    var outcome = await hub.SendWindowsNativeNotificationAsync(toast);
    Console.WriteLine(outcome.State);
    
    foreach (RegistrationResult result in outcome.Results)
    {
        Console.WriteLine(result.ApplicationPlatform + "\n" + result.RegistrationId + "\n" + result.Outcome);
    }
    

    我建议阅读 Microsoft 的 Diagnose dropped notifications in Azure Notification Hubs 文档以进行一些自我诊断并解决您面临的问题。另请阅读Send push notifications to Flutter apps using Azure Notification Hubs via a backend service 文档了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-30
      • 1970-01-01
      • 2018-08-09
      • 1970-01-01
      • 2021-09-16
      • 2018-10-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多