iOS NotificationReceiving not fired when app is not in foreground
PauchardThomas opened this issue · 5 comments
Describe the bug
Hello,
On iOS, NotificationReceiving is not fired when app is not in foreground...
I would like to show a local notification at 10:00 am each day except for the week-end (saturday/sunday).
The following code is not working, i'm still received the local notification on saturday / sunday when the app is closed or in the background :
if (await LocalNotificationCenter.Current.AreNotificationsEnabled() == false)
{
await LocalNotificationCenter.Current.RequestNotificationPermission();
}
LocalNotificationCenter.Current.NotificationReceiving = (request) =>
{
var isWeekend = DateTime.Now.DayOfWeek == DayOfWeek.Sunday || DateTime.Now.DayOfWeek == DayOfWeek.Saturday;
return Task.FromResult(new NotificationEventReceivingArgs
{
Handled =isWeekend,
Request = request
});
};
var notification = new NotificationRequest
{
NotificationId = 100,
Title = "My Title",
Description = $"My description",
Schedule =
{
NotifyTime = DateTime.Now.AddSeconds(15), // Used for Scheduling local notification, if not specified notification will show immediately.
RepeatType = NotificationRepeat.Daily
}
};
await LocalNotificationCenter.Current.Show(notification);
Any idea please ?
Thanks
Platform (please complete the following information):
- XF 5.0.0.244
- Plugin.LocalNotification 10.1.8
Smartphone (please complete the following information):
- Device: iPhone 13 mini
- OS: iOS 16.6
@PauchardThomas So NotificationReceiving is only fired when the app is in the foreground?
@thudugala Exactly
@PauchardThomas can you attach a sample project?
@thudugala https://github.com/PauchardThomas/PluginLocalNotification-Issue-441
- Launch the app
- Accept notifications
- You will receive the notification
- Close the app
- Go to settings, change the day
- Problem : You will receive the notification even on saturday and sunday
@PauchardThomas The workaround for now is to schedule 5 notifications NotificationRepeat.Weekly
. Make sure NotifyTime .DayOfWeek
is set correctly.