[iOS] Temporary Workaround for Black Launch Screen Bug After Several Launches
Temporary workaround to solve XCode Build & Run app black screen issue
Photo by Etienne Girardet
Issue
I don’t know when XCode started (maybe 14?) some projects will freeze on a black screen after multiple Build & Run on the simulator. The status stays at “Launching Application…” without any response; even rebuilding and running again doesn’t work, manual termination of the entire simulator is required to restart and fix it.
XCode 14.1: Stuck at “Launching Ap… | Apple Developer Forums Hello team, On Xcode 14.1, After building the project and when the simulator launches, it shows blank black screen… forums.developer.apple.com
New projects or projects with fewer settings encounter this issue less frequently; older projects face it more often, but due to their long history and complex settings, no definite root cause can be found through online searches, mostly speculated to be an XCode Bug (or M1?). However, this issue is very annoying, as during frequent Build & Run to check progress, the result is a black screen, requiring a complete restart each time, wasting about 1-2 minutes, disrupting development flow.
Workaround
Here is a workaround to navigate around this issue. Since we can’t avoid the black screen problem and it doesn’t occur on the first launch of the simulator during Build & Run, we just need to ensure that each Build & Run is on a freshly restarted simulator.
First, we need to obtain the Device UUID
of the simulator you want to run
Run the following command in Terminal:
1
xcrun simctl list devices
- Find the emulator device you want to use and its Device UUID.
- Here is an example with my iPhone 15 Pro (iOS 17.5): Device UUID =
08C43D34–9BF0–42CF-B1B9–1E92838413CC
Next, we will create an auto-reboot.sh
Shell Script file
cd /directory/where/you/want/to/place/this/script/
vi auto-reboot.sh
Paste the following script:
- Replace
[Device UUID]
with the Device UUID of the emulator you want to use - Remember to update this script with the new Device UUID if you change the emulator, or it will not work
1
2
3
4
5
6
7
8
9
10
#!/bin/bash
## Use the command below to find the Device UUID of the simulator you want to use:
## xcrun simctl list devices
# shutdown simulator
xcrun simctl shutdown [Device UUID]
# reboot simulator
xcrun simctl boot [Device UUID]
- The script is straightforward, it shuts down and reboots the specified emulator
ESC
&:wq!
Adjust the execution permission of auto-reboot.sh
:
1
chmod +x auto-reboot.sh
Return to XCode Settings
Since everyone has different preferences for emulators, I set this up in XCode Behaviors. This won’t affect project settings or impact team members on git. However, for a simple and team-wide synchronization, you can directly set it in Scheme -> Build -> Pre-actions -> sh /directory/where/you/want/to/place/this/script/auto-reboot.sh
.
XCode Behaviors
XCode -> Behaviors -> Edit Behaviors…
- Find the
Running
section - Choose the
Completes
option Completion Trigger = Stop or Rebuild Check
Run
on the right- Choose
Choose Script…
and select the location of the newly createdauto-reboot.sh
file - Finish
Principle and Conclusion
We use XCode Behaviors to restart the emulator at the Completes (Stop or Rebuild) trigger point, just before starting the Build. This process almost always completes the restart before the Build -> Run finishes.
If you repeatedly restart, there is a chance of a slow restart, causing another black screen issue when running. However, this scenario is not considered, as this solution ensures normal execution of Build & Run App in daily use.
In terms of speed impact, I think it’s acceptable because Build & Run itself takes some time, which is usually enough time for the emulator to restart.
If you have any questions or feedback, feel free to contact me.
===
===
This article was first published in Traditional Chinese on Medium ➡️ View Here