Xamarin.Forms iOS DidReceiveNotificationResponse 未调用

问题描述 投票:0回答:1

我正在尝试在我的 Xamarin.Forms iOS 应用程序中使用本地通知。

通知是可见的,但是当我点击通知时,根本没有调用 DidReceiveNotificationResponse。这里没有显示管理授权的代码,但它是正确的。

我已经阅读了这里和其他地方关于这个问题的所有帖子,这些帖子与委托问题(未分配)有关。

这是我的代码:

[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate, IUNUserNotificationCenterDelegate
{
    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        Popup.Init();
        global::Xamarin.Forms.Forms.Init();

        UNUserNotificationCenter.Current.Delegate = this;

        ...
    }

    [Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]
    public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, System.Action completionHandler)
    {
        if (response.IsDefaultAction)
        {
            if (response.Notification.Request.Content.UserInfo.ContainsKey(new NSString("remainingTime")))
            {
                Locator.GetSharedInstance<IAlertDelayedService>().RaiseOpenAlertDelayedPopupEvent();
            }

        }
        completionHandler();
    }

    [Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
    public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, System.Action<UNNotificationPresentationOptions> completionHandler)
    {
        completionHandler(UNNotificationPresentationOptions.Alert);
    }

}
c# ios xamarin.forms xamarin.ios
1个回答
0
投票

我在 Xamarin.Forms 通知示例中找到了解决方案here。 它使用 UNUserNotificationCenterDelegate 派生类 来处理收到和点击的通知。

© www.soinside.com 2019 - 2024. All rights reserved.