Xamarin的.表单iOS没有调用DidReceiveNotificationResponse.



我正在尝试在Xamarin中使用本地通知。form iOS application.

通知是可见的,但是当我点击通知时,根本没有调用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);
}
}

我在Xamarin中找到了一个解决方案。表单通知示例在这里。它使用一个UNUserNotificationCenterDelegate派生类来处理接收和点击的通知。

最新更新