Local Notification not working in Background Mode

I have implemented chat functionality in my app, as remote notifications are not possible to send from server side, i am using local notification to alert the user of new incoming message. Everything works fine in simulator, i can see notifications are displayed in foreground as well as background mode.

But when i run the app on device, notification are only working in foreground mode. When app is in background, notifications wont show.

After investigating this issue i found that they work fine when app is running in debug mode(i.e. launched from Xcode and cable still attached). But as soon as i disconnect the cable, they wont show anymore.

Below is the code i have tested, both the code produces the same result. (FYI: It's a Xamarin.IOS app)

Code Block language
code-block


UILocalNotification localNotification = new UILocalNotification();
localNotification.FireDate = NSDate.Now;
localNotification.TimeZone = NSTimeZone.DefaultTimeZone;
localNotification.AlertBody = message;
localNotification.SoundName = UILocalNotification.DefaultSoundName;
localNotification.UserInfo = dict;
UIApplication.SharedApplication.ScheduleLocalNotification(localNotification);

Code Block language
code-block


var content = new UNMutableNotificationContent();
content.Body = body;
content.Sound = UNNotificationSound.Default;
Code Block
var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(1, false);

var requestID = "Chat";
var request = UNNotificationRequest.FromIdentifier(requestID, content, trigger);
Code Block
// schedule it
UNUserNotificationCenter.Current.AddNotificationRequest(request, (error) =>
{
if (error != null)
{
Console.WriteLine($"Error: {error.LocalizedDescription ?? ""}");
}
else
{
Console.WriteLine("Scheduled...");
}
});

After researching on this issue on other forums lot of people has suggested to add this line in AppDelegate
application.BeginBackgroundTask("showNotification", expirationHandler: nil); but since it is not allowed for expirationHandler to be nil anymore. I tried calling EndBackgroundTask but still notification are not working in Background mode.

I also tried calling my Schedule Notification code from BeginBackgroundTask on my controller but it didn't work either.
Does anyone has any idea on how to make local Notification work in background mode in IOS13.


Did you ever find a fix for this? I have the same issue - works fine on simulator even in background but when deployed to phone nothing happens when watch is not on the app.
Local Notification not working in Background Mode
 
 
Q