I've seen a lot a similar questions but I have not found an answer to this specific scenario while running on Mac. If the app is off and a user notification comes in and the user taps on it, then the app is opened. Once the app is opened, how can it capture the notification so that it can handle its contents.
From what I can tell, the notification cannot be retrieved from [[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler: or [[UNUserNotificationCenter currentNotificationCenter] getPendingNotificationRequestsWithCompletionHandler:.
When the app is opened from the user tapping on the notification, it also does not seem to open through the UNUserNotificationCenterDelegate functions. I don't see it in either willPresentNotification or didReceiveNotificationResponse and it's not handled by the appDelegate's didReceiveRemoteNotification:fetchCompletionHandler
On iOS in this situation, the notification arrives inside the launchOptions from application:didFinishLaunchingWithOptions. There's key UIApplicationLaunchOptionsRemoteNotificationKey contains the notification data. The same app running on Mac contains a nil launchOptions dictionary.
These are all the places that I've looked but I'm sure I must be missing something.
While the OS knows it needs to wake up the app because some tapped on a notification, your app is likely setup too late for being the
UserNotificationCenterDelegate.See docs:
Like what's happening now for you is:
didFinishLaunchingthe delegate isn't set yet, sodidReceiveNotificationResponseisn't called.tldr for any delegate/callback that can wake up the app (e.g. UserNotification, CoreLocation, etc.), the setup/registration for the callbacks needs to happen before
didFinishLaunching