Testing openURL to cold started app

Is it possible to tell Xcode to run an app as though it was opened from a URL?


I have an issue when opening the app from a URL (deep link) when the app is not in device memory and is "cold started". If the app is already in memory, the UI is initialized to a point that allows opening of the URL without issues. In order to correct my code, I was hoping to test opening the app from a deep link after it has been killed from the app switcher. In order to have debugger access during the start up process so that I can see the process in action, I would need to instruct Xcode to start the app as though it was opening from a deep link.


Can this be done?

Post not yet marked as solved Up vote post of themacolyte Down vote post of themacolyte
7.9k views

Replies

After some more work, I've found that this can be accomplished with mixed success.

Run the app from Xcode to install it on your device and then stop it from Xcode.

Force quit the app from the app switcher UI on the device.

Navigate to the scheme for the project in Xcode. Under the Run section's Info tab, there is a radio button for "Wait for executable to be launched". Make sure this is checked instead of the "Automatically" option.


Run the app from Xcode. It will not open on the device, but the debugger will wait for it to open and then it will attach to it.


So, while the debugger is waiting, you can open an app like Notes where you have a deep link and touch the link to cause the app to open. If you have breakpoints set somewhere, like in application:didFinishLaunchingWithOptions:, you can follow the startup process.


Issues I've found so far:

- NSLog statements do not output to the console, so if you didn't have any breakpoints set, it would appear as though the debugger had not attached to the app at all.

- It has a high probability of causing issues on my device. At one point, the screen would not turn on although all other indicators showed the device was on and accessible (iTunes picked it up right away, my Apple Watch indicated it was still connected, Xcode still indicated it was connected). The screen would not turn on until after a hard reboot. In another case, Notes became unresponsive. So for now, it seems best to do one round of testing and then reboot the device.

As of iOS 16.4, macOS 13.3, and Xcode 14.3, new XCTest UI Testing API's are available which let you test this very easily.

You can open your application with a specific URL: https://developer.apple.com/documentation/xctest/xcuiapplication/4108226-open

Or, open any URL in the default application for it: https://developer.apple.com/documentation/xctest/xcuisystem/4108234-open