question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Foreground alerts not working on iOS - UNUserNotificationCenter.Current.Delegate never set

See original GitHub issue

Describe the bug When and app is foregrounded, local notifications are not processed. This is because UNUserNotificationCenter.Current.Delegate is never set.

You can work around this by adding the following to your AppDelegate:

LocalNotificationCenter.SetCustomUserNotificationCenterDelegate();

This is a super confusing part of local notification on iOS. This delegate is required for alerts to work in the foreground.

https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate

Use the methods of the UNUserNotificationCenterDelegate protocol to handle user-selected actions from notifications, and to process notifications that arrive when your app is running in the foreground. After implementing these methods in an object, assign that object to the delegate property of the shared UNUserNotificationCenter object. The user notification center object calls the methods of your delegate at appropriate times.

To Reproduce Trigger an alert that triggers immediately:

  var result = await LocalNotificationCenter.Current.Show(new NotificationRequest()
  {
      Title = title,
      iOS = new iOSOptions()
      {
          Priority = iOSPriority.TimeSensitive,
          HideForegroundAlert = false
      },
      Description = description,
      NotificationId = notificationId
  });

Expected behavior Alert should show, but does not.

Screenshots n/a

Platform (please complete the following information):

  • OS: iOS
  • Version 10+

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
EdwardMcFlurrycommented, Nov 5, 2022

🕺🏻 I figured it out 😎 using the following…

Priority = iOSPriority.Critical, for iOSOptions.

Hope this helps!

0reactions
thudugalacommented, Nov 29, 2022

Try version 10.0.3

Read more comments on GitHub >

github_iconTop Results From Across the Web

UNUserNotifications never show up
The code is in my AppDelegate.swift, and I have declared the "center" argument in didFinishLaunchingWithOptions. private func application(_ application: ...
Read more >
iOS 10 UNUserNotificationCenterDelegate not called. push ...
This answer pertains to iOS 10+, using the UserNotifications framework. You need a class to conform to the UNUserNotificationCenterDelegate ...
Read more >
iOS Silent APNS push notification does not go thru
I am experiencing the Apns silent background notification sent with pushtype="background", priority="5", contentavailable=true never reaches the ...
Read more >
Pusher Beams Docs | Handling incoming iOS notifications
Use Beams to send iOS notifications and trigger callback code in your app when a notification is recieved so that you can respond...
Read more >
Can't recived notification when foreground · Issue #295
My issue: I received Warning: Application delegate received call to ... //Called when a notification is delivered to a foreground app.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found