Foreground alerts not working on iOS - UNUserNotificationCenter.Current.Delegate never set
See original GitHub issueDescribe the bug When and app is foregrounded, local notifications are not processed. This is because UNUserNotificationCenter.Current.Delegate is never set.
You can work around this by adding the following to your AppDelegate:
LocalNotificationCenter.SetCustomUserNotificationCenterDelegate();
This is a super confusing part of local notification on iOS. This delegate is required for alerts to work in the foreground.
https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate
Use the methods of the UNUserNotificationCenterDelegate protocol to handle user-selected actions from notifications, and to process notifications that arrive when your app is running in the foreground. After implementing these methods in an object, assign that object to the delegate property of the shared UNUserNotificationCenter object. The user notification center object calls the methods of your delegate at appropriate times.
To Reproduce Trigger an alert that triggers immediately:
var result = await LocalNotificationCenter.Current.Show(new NotificationRequest()
{
Title = title,
iOS = new iOSOptions()
{
Priority = iOSPriority.TimeSensitive,
HideForegroundAlert = false
},
Description = description,
NotificationId = notificationId
});
Expected behavior Alert should show, but does not.
Screenshots n/a
Platform (please complete the following information):
- OS: iOS
- Version 10+
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:10 (4 by maintainers)
🕺🏻 I figured it out 😎 using the following…
Priority = iOSPriority.Critical, for iOSOptions.
Hope this helps!
Try version 10.0.3