Handle a deep link URL in SceneDelegate and navigate to order detail.

iOS scene-based deep links.
Handles willConnectTo and openURLContexts; parses path with URLComponents; validates ID; pushes detail onto nav stack.
Forgetting warm launches or routing without checking view hierarchy.
WHAT THIS TESTS: This question tests whether you understand the modern iOS scene-based lifecycle for URL handling and can distinguish between cold-start and warm-launch deep-link entry points. Interviewers want to see that you know SceneDelegate is the correct starting point on iOS 13 and later, and that you recognize navigation requires a valid view hierarchy.
A GOOD ANSWER COVERS: First, state that there are two possible entry points. For a cold start, the URL arrives inside scene willConnectTo session options via connectionOptions.urlContexts. For a warm launch while the scene is already active, the system calls scene openURLContexts instead. Second, extract the UIOpenURLContext and pull out the URL. Third, use URLComponents to parse the path components rather than naive string splitting, so you safely extract orders and the identifier 451. Fourth, validate the identifier, for example ensuring it is numeric and non-empty. Fifth, access the root view controller, verify it is embedded in a UINavigationController or suitable container, and push or set the order detail view controller. If the app uses a coordinator or router pattern, mention delegating to that module.
COMMON WRONG ANSWERS: A major red flag is only mentioning willConnectTo and completely forgetting openURLContexts, which means the deep link fails if the app is already running. Another is trying to handle the URL in the old AppDelegate application openURL method without scene awareness. Some candidates suggest parsing the URL with string separation by slash rather than URLComponents, which is brittle. Attempting to navigate before the root view controller hierarchy is ready, or force unwrapping view controllers, also signals a lack of production experience.
LIKELY FOLLOW-UPS: The interviewer may ask how you would handle a universal link instead of a custom URL scheme, or how you would route the URL if the user is not logged in and must first pass through an authentication flow. They might also ask how to test this in the simulator, or how you would support iOS 12 and earlier where AppDelegate is still responsible.
ONE CONCRETE EXAMPLE: Imagine the user taps myapp://orders/451 while the app is terminated. The system creates the UIWindowScene and calls scene willConnectTo session with connectionOptions. You iterate over connectionOptions.urlContexts, grab the first URL, create URLComponents from it, and read pathComponents. You check that pathComponents contains orders at index one and that pathComponents two is a valid integer. You then instantiate OrderDetailViewController with orderId 451, grab the root UINavigationController from the window, and call pushViewController animated true. If the app were already foregrounded, the same parsing logic would run inside scene openURLContexts.
Source: developer.apple.com
Read the original → developer.apple.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.