英文:
Xamarin.Forms iOS DidReceiveNotificationResponse not called
问题
I am trying to use local notifications in my Xamarin.Forms iOS application. The notification is visible, but when I tap the notification, DidReceiveNotificationResponse is not called at all. The code that manages the authorization is not shown here but it is correct. I have read all the posts here and elsewhere about this problem that seams to be related to a delegate issue (not assigned). Here is my code:
[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);
}
}
英文:
I am trying to use local notifications in my Xamarin.Forms iOS application.
The notification is visible, but when I tap the notification, DidReceiveNotificationResponse is not called at all. The code that manages the authorization is not shown here but it is correct.
I have read all the posts here and elsewhere about this problem that seams to be related to a delegate issue (not assigned).
Here is my code:
[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);
}
}
答案1
得分: 0
I have found a solution in a Xamarin.Forms notification sample here.
It uses a UNUserNotificationCenterDelegate derived class to handle the received and tapped notifications.
英文:
I have found a solution in a Xamarin.Forms notification sample here.
It uses a UNUserNotificationCenterDelegate derived class to handle the received and tapped notifications.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论