I am currently migrating an app to the new UserNotifications framework. I'm stuck at detecting if the app was launched due to the user opening a local notification. The test case is:
The problem is that in this case userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:
is not called. In application:didFinishLaunchingWithOptions:
there is a key UIApplicationLaunchOptionsLocalNotificationKey
which contains an object of type UIConcreteLocalNotification
which is a subclass of UILocalNotification
. However, as part of the old notification system, UILocalNotification
is deprecated and we are not supposed to use it. I dug in the documentation and the web and did not find an answer to my question:
How do I find if an app was launched due to a local notification?
How do I obtain that notification?
Make sure you're assigning your implementation of UNUserNotificationCenterDelegate
to UNUserNotificationCenter.current()
before your app finishes launching, as it says in the documentation.
Then you should be getting a call to your UNUserNotificationCenterDelegate
's userNotificationCenter(_:didReceive:withCompletionHandler:)
at app launch with the response object, which contains the original notification. For me, it happened some time after my application(_:didFinishLaunchingWithOptions:)
was called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With