Routing a notification tap on cold start

Platform & distribution Senior Swift 5.0+ iOS 17+ Reviewed By Alok Singh

Pick the fix

Tapping a notification while the app is killed opens the home screen instead of the chat. Most likely fix?

Options
Hint 1 of 1

When is the tap delivered?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Set the notification center delegate in didFinishLaunching and queue the route until the root UI is ready

Correct. The tap is received and delivered when the UI can show it.

Why not the others?
  • B Set the delegate in the chat screen's viewDidLoad. That screen doesn't exist at cold start.
  • C Send a second silent push after launch. It's unreliable and throttled.
  • D Read the payload from UserDefaults. Nothing writes it there.

30-second answer

Set the UNUserNotificationCenter delegate before application(_:didFinishLaunchingWithOptions:) returns, so userNotificationCenter(_:didReceive:) receives the tap even on cold start. Turn the payload into a route and hand it to the same router used for deep links; if the UI or login isn't ready yet, queue the route and deliver it once it is.

Practise saying it · 45 s. No recording, just a timer

Explain cold-start notification routing.

Say your answer out loud, then check which of these points you covered:

  • Delegate set at launch
  • Payload to route
  • Queue until ready

Deep dive

Call the completion handler after handling the response.

Include a route or entity id in the payload, not UI instructions.

Test cold start from a killed app, not just from the background.

In SwiftUI, use an app delegate adaptor to set the delegate early.

Common mistakes

  • Setting the delegate in a view controller, too late for cold start.
  • Pushing screens before the root UI exists.

Senior take & follow-ups

Seniors reuse one router and buffer routes until the app is ready.

Follow-up questions

Think of your answer first, then open the hint.

  1. Why set the delegate so early?

    Show hint

    The tap is delivered during launch.

  2. How do you test it?

    Show hint

    Kill the app, send a push, tap it.

Suggest a fix if something here is wrong or out of date.