Handle event of returning to iOS app from local notification?

283 views Asked by At

My iOS app sets a local notification that only goes off if the app is in the background.

When the user selects this local notification it brings the app back to the foreground.

Is it possible to subscribe to an event in NotificationCenter to handle the event of the user coming from this specific path maybe through a standard UIApplicationmethod?

If not, what is the best way to handle the specific event where a user taps a local notification ideally in the ViewController presented on foregrounding in Swift 5?

1

There are 1 answers

0
David Ansermot On

Create a delegate object that adopts the UNUserNotificationCenterDelegate protocol and implement the userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: methods.

Assign this object to the delegate property of the singleton UNUserNotificationCenter object.

Do this in you AppDelegate didFinishLaunching method

Additional doc : https://developer.apple.com/documentation/usernotifications/unusernotificationcenter