Hello,
I'm using local notifications and I noticed notifications on iOS only appear when the app is in background (am i right ?).
But in my case i want the notifications even when the app is in foreground.
I saw that shouldAlwaysAlertWhileAppIsForeground settings is on "NO" so i tried to turn it to "YES" like that =>
UNUserNotificationCenter.Current.GetNotificationSettings((settings) => {
settings.SetValueForKey(new NSString("YES"), new NSString("shouldAlwaysAlertWhileAppIsForeground"));
});
But it makes crash the app ...
Any tips to make it work ?
Thanks !
Posts
on iOS 11 we can implement the
IUNUserNotificationCenterDelegate
to show the notification alert when our app is on foreground state. Your AppDelegate.cs can be like this:WillPresentNotification
called to deliver a notification to an application that is running in the foreground. AndDidReceiveNotificationResponse
will be fired when user taps the notification even though app is on the foreground.I tried this in my AppDelegate without success ...
It is strange though because the code run without error
Even success =>
But nothing in the notification center ...
UNUserNotificationCenter.Current.AddNotificationRequest
this method just adds a local notification to your notification center. If you want to show this notification when app is on the foreground. You should implementIUNUserNotificationCenterDelegate
we talked above. To trigger these two events when notification comes, you should set the delegate when you register the notification:UNUserNotificationCenter.Current.Delegate = this;
in the AppDelegate.Oh yeah right i forgot this
Now notifications show in foreground too !
Thank you !