Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS NotificationReceiving not fired when app is not in foreground #441

Open
PauchardThomas opened this issue Aug 11, 2023 · 5 comments
Open
Assignees
Labels
bug Something isn't working iOS iOS only issue

Comments

@PauchardThomas
Copy link

PauchardThomas commented Aug 11, 2023

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 PauchardThomas added the bug Something isn't working label Aug 11, 2023
@PauchardThomas PauchardThomas changed the title iOS NotificationReceiving not fired when app is in background iOS NotificationReceiving not fired when app is not in foreground Aug 11, 2023
@thudugala
Copy link
Owner

@PauchardThomas So NotificationReceiving is only fired when the app is in the foreground?

@PauchardThomas
Copy link
Author

@thudugala Exactly

@thudugala
Copy link
Owner

@PauchardThomas can you attach a sample project?

@PauchardThomas
Copy link
Author

@thudugala https://github.com/PauchardThomas/PluginLocalNotification-Issue-441

  1. Launch the app
  2. Accept notifications
  3. You will receive the notification
  4. Close the app
  5. Go to settings, change the day
  6. Problem : You will receive the notification even on saturday and sunday

@thudugala thudugala added the iOS iOS only issue label Sep 29, 2023
@thudugala
Copy link
Owner

@PauchardThomas The workaround for now is to schedule 5 notifications NotificationRepeat.Weekly. Make sure NotifyTime .DayOfWeek is set correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working iOS iOS only issue
Projects
None yet
Development

No branches or pull requests

2 participants