【发布时间】: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