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

Notification Receiving not working on iOS when in foreground #414

Open
gsk143 opened this issue Jun 6, 2023 · 21 comments
Open

Notification Receiving not working on iOS when in foreground #414

gsk143 opened this issue Jun 6, 2023 · 21 comments
Assignees
Labels
bug Something isn't working iOS iOS only issue

Comments

@gsk143
Copy link

gsk143 commented Jun 6, 2023

Describe the bug
Notification Receiving not working on iOS

To Reproduce
Use sample code in the repo and add
LocalNotificationCenter.Current.NotificationReceived += NotificationRecived;

private void NotificationRecived(NotificationEventArgs e) { MainThread.BeginInvokeOnMainThread(() => Shell.Current.DisplayAlert(GlobalConstants.Notification.SyncNotificationTitle, GlobalConstants.Notification.SyncNotificationDesc, AppRes.Ok)); }

Expected behavior
Should fire the event in the foreground and the user can do his logic

Platform:

  • OS: iOS
  • Version 16.2
@gsk143 gsk143 added the bug Something isn't working label Jun 6, 2023
@gsk143
Copy link
Author

gsk143 commented Jun 7, 2023

Workaround: Add this to the class linked below
public async override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { //Do your logic }

#334 (comment)

@thudugala thudugala added the iOS iOS only issue label Jun 16, 2023
thudugala added a commit that referenced this issue Jun 16, 2023
Notification not working on iOS
@thudugala
Copy link
Owner

thudugala commented Jun 17, 2023

@gsk143 please try version 10.1.6

@LeoJHarris
Copy link

@thudugala struggling with this issue, 10.1.6 did seem to resolve the issue unfortunately. Others maybe able to also confirm this.

@thudugala
Copy link
Owner

thudugala commented Jun 25, 2023

@LeoJHarris Are you having the issue in Xamarin or .NET Maui ?

@LeoJHarris
Copy link

@LeoJHarris Are having the issue in Xamarin or .NET Maui ?

@thudugala issue is in Xamarin Forms. Using latest of this library.

@thudugala
Copy link
Owner

thudugala commented Jun 27, 2023

@LeoJHarris Please try version 10.1.7

Make sure to call LocalNotificationCenter.SetUserNotificationCenterDelegate();

https://github.com/thudugala/Plugin.LocalNotification/wiki/Usage-10.0.0-Xamarin.Forms

@LeoJHarris
Copy link

LeoJHarris commented Jun 29, 2023

@thudugala still not working iOS. LocalNotificationCenter.SetUserNotificationCenterDelegate(); was already being included. Side note, I can confirm the notification permission is granted.

@thudugala
Copy link
Owner

Hey @LeoJHarris can you attach a sample project?

@thudugala
Copy link
Owner

Recording.2023-06-30.011418.mp4

@LeoJHarris
Copy link

@thudugala I'm not too sure which NuGet version your using in that sample screen but I pulled your repo and ran the NuGet sample project, updated the NuGet package from 8.0.2 (notifications working) => 10.1.8 (notifications not working):

NuGet.zip

@thudugala
Copy link
Owner

thudugala commented Jul 6, 2023

@LeoJHarris

Make sure to call LocalNotificationCenter.SetUserNotificationCenterDelegate();

https://github.com/thudugala/Plugin.LocalNotification/wiki/2.-Usage-10.0.0-Xamarin.Forms

@LeoJHarris
Copy link

LeoJHarris commented Jul 6, 2023

@thudugala

Have now added LocalNotificationCenter.SetUserNotificationCenterDelegate(); In AppDelegate class and still not receiving any notification on iOS, see attached sample

NuGet.zip

Its still the same sample project that was updated from 8.0.2 (notifications working) => 10.1.8 (notifications not working and calls LocalNotificationCenter.SetUserNotificationCenterDelegate();)

@thudugala
Copy link
Owner

thudugala commented Jul 7, 2023

@LeoJHarris

Please read the doc fully

https://github.com/thudugala/Plugin.LocalNotification/wiki/2.-Usage-10.0.0-Xamarin.Forms

you need to request Permission

if (await LocalNotificationCenter.Current.AreNotificationsEnabled() == false)
{
    await LocalNotificationCenter.Current.RequestNotificationPermission();
}

@LeoJHarris
Copy link

LeoJHarris commented Jul 9, 2023

@thudugala thanks for assisting, its working now if I call:

await LocalNotificationCenter.Current.Show(request).ConfigureAwait(true);

but using DI does not work which I had been doing previously:

_notificationService.Show(request).ConfigureAwait(true))

I registered the service like this:

containerRegistry.RegisterInstance(LocalNotificationCenter.Current);

Another comment here #334 (comment) pointed out using Dependency Injection was not working with this plugin. Is there a way to register and use with DI?

iOS seems not to be working with DI, android is okay.

@thudugala
Copy link
Owner

Will look into it as soon as possible next week.

@thudugala
Copy link
Owner

@LeoJHarris for Xamarin Forms, you must register this plugin to the DI by yourself. It's only registered automatically in .Net MAUI

@LeoJHarris
Copy link

@thudugala I am already doing the DI like this:

_ = containerRegistry.RegisterInstance(LocalNotificationCenter.Current);

@thudugala
Copy link
Owner

,@LeoJHarris can attach a sample project?

@nikubesliu
Copy link

nikubesliu commented Aug 2, 2023

Hello,
I have the same problem on 10.1.8 with xamarin.forms ios
On simulator notification pops up when app is in foreground, but on real device doesn't.
Is there a workaround for that? Thank you.

@thudugala
Copy link
Owner

@nikubesliu is permission granted to show notifications?

Can you attach a sample project?

@LeoJHarris
Copy link

@thudugala Sorry I havnt been able to get reproduce this in a small sample application, seemed to occur in the production app we have but Ill need to double check things again when I have time.

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

4 participants