我正在尝试在我的 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);
}
}