【问题标题】:.Net Maui iOS app with Push Notifications WillPresentNotification or DidReceiveNotificationResponse never gets called带有推送通知 WillPresentNotification 或 DidReceiveNotificationResponse 的 .Net Maui iOS 应用永远不会被调用
【发布时间】:2022-11-21 01:30:02
【问题描述】:

我可以调用 RegisterForRemoteNotifications();从 AppDelegate 获取令牌。然后我使用我构建的 APN 服务器来更新 Apple Passes。我正在发送一条消息,其中包含正确的有效负载、标头等...,但什么也没有发生。

我假设需要将某些内容添加到 MauiProgram.cs 才能使其正常工作。

鉴于我有自己的 APN 服务器,我现在真的不想使用 Firebase 或 Azure Notification Hub。以下链接提供了 Firebase 方法。

[https://cedricgabrang.medium.com/firebase-push-notifications-in-net-maui-ios-2f4388bf1ac][1]

由于本地通知和远程通知使用相同的方法,因此我按照这个示例对代码进行了建模。

https://github.com/xamarin/xamarin-forms-samples/tree/main/LocalNotifications

这是我的一些装饰代码。

        // Called if app is in the foreground.
        [Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
        public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
        {
            SentrySdk.CaptureMessage("WillPresentNotification = " + "yes");

            ProcessNotification(notification);
            completionHandler(UNNotificationPresentationOptions.Alert);
        }

        // Called if app is in the background, or killed state.
        [Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]
        public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
        {
            SentrySdk.CaptureMessage("DidReceiveNotificationResponse = " + "yes");

            if (response.IsDefaultAction)
            {
                ProcessNotification(response.Notification);
            }
            completionHandler();
        }

注意:我正在使用 Azure DevOps 管道编译我的 iOS 应用程序。我已将开发证书和推送通知证书添加到钥匙串中。我没有看到 DotNetCoreCLI@2 任务中包含的推送通知证书。推送通知在供应配置文件中启用和配置。构建过程以及钥匙串如何安装/使用所有证书可能存在问题。

有谁知道如何使这项工作?看起来这应该很容易做到。

【问题讨论】:

    标签: xamarin.ios azure-pipelines .net-maui unusernotificationcenter


    【解决方案1】:

    我终于使用 .Net Maui 的 Firebase.plugin 完成了这项工作。我的 APN 服务器仍然无法工作。我正在使用 Firebase 控制台发送消息。

    我使用了这些说明。

    https://cedricgabrang.medium.com/firebase-push-notifications-in-net-maui-ios-2f4388bf1ac

    如果您在 iOS 上构建 Firebase.plugin 时遇到问题,请查看此问题。 https://github.com/TobiasBuchholz/Plugin.Firebase/issues/51

    这是我在 Azure Pipeline 中用于合并两个 Apple 证书的代码。 https://stackoverflow.com/a/74105887/5360237

    【讨论】:

      猜你喜欢
      • 2017-02-04
      • 2016-08-08
      • 1970-01-01
      • 2020-10-13
      • 2020-11-14
      • 1970-01-01
      • 1970-01-01
      • 2013-12-01
      • 1970-01-01
      相关资源
      最近更新 更多