Post

iOS Temporary Workaround|Fix Black Launch Screen Bug After Multiple Launches

iOS developers facing the black launch screen bug after several app launches can apply this temporary workaround to bypass XCode build and run issues, ensuring smoother app testing and faster iteration cycles.

iOS Temporary Workaround|Fix Black Launch Screen Bug After Multiple Launches

点击这里查看本文章简体中文版本。

點擊這裡查看本文章正體中文版本。

This post was translated with AI assistance — let me know if anything sounds off!


[iOS] Temporary Workaround for Black Launch Screen Bug After Several Launches

Temporary Workaround to Fix XCode Build & Run App Stuck on Black Screen Issue

Photo by [Etienne Girardet](https://unsplash.com/@etiennegirardet?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash){:target="_blank"}

Photo by Etienne Girardet

Question

Not sure which XCode version started this (probably 14?), but some projects freeze on a black screen after multiple Build & Run attempts on the simulator. The status gets stuck at Launching Application… with no response; rebuilding and rerunning doesn’t help. You need to manually kill the entire simulator and restart it to fix the issue.

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 and new project settings rarely encounter this issue; older projects face it more often. However, due to their long history and complex settings, no definite root cause can be found online. It is mostly suspected to be an XCode bug (or M1?). This problem is very annoying because when building and running to check results, the screen often goes black, forcing a complete restart. Each time wastes about 1–2 minutes and disrupts development.

Workaround

Here is a workaround based on the idea that if we can’t avoid the black screen issue, and the black screen does not appear during the first Build & Run on the simulator, then we just need to ensure that each Build & Run uses a freshly restarted simulator.

First, we need to get the Device UUID of the simulator you want to run.

Run in Terminal:

1
xcrun simctl list devices

  • Find the emulator device you want to use and its Device UUID

  • Here I use my iPhone 15 Pro (iOS 17.5) as an example
    Device UUID = 08C43D34–9BF0–42CF-B1B9–1E92838413CC

Next, let’s add a new auto-reboot.sh Shell Script file

  • cd /The 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 simulator you want to use.

  • Remember to update the Device UUID in this script if the simulator is changed; otherwise, 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 logic is straightforward: just close & restart the emulator you want to use.

  • ESC & :wq!

Adjust auto-reboot.sh Execution Permissions:

1
chmod +x auto-reboot.sh

Back to XCode Settings

Because everyone uses different simulators, I set it in XCode Behaviors to avoid changing the project settings or affecting the team via git; however, for a simple, team-wide sync, you can set it directly in Scheme -> Build -> Pre-actions -> sh /path/to/your/script/auto-reboot.sh.

XCode Behaviors

  • XCode -> Behaviors -> Edit Behaviors…

  • Find the Running section

  • Select the Completes option
    Completes timing = Stop or Rebuild

  • Check Run on the right side

  • Choose Choose Script… to select the location of the newly created auto-reboot.sh file.

  • Completed

Principle and Conclusion

Demo is a clean project, so the build time is very short

The demo is a clean project, so the build time is very short.

We use XCode Behaviors to restart the simulator at the Completes (Stop or Rebuild) stage, before the Build starts. This almost always completes the restart before the Build -> Run finishes.

If you repeatedly press restart, it may cause the reboot to be too slow, resulting in Run not finding the target and causing another type of black screen. However, this situation will not be considered. At least this solution can keep Build & Run App running normally during daily use.

The impact on speed is fine, because Build & Run itself takes some time, which is enough time for the emulator to restart.

If you have any questions or suggestions, feel free to contact me.


Buy me a beer

This post was originally published on Medium (View original post), and automatically converted and synced by ZMediumToMarkdown.

Improve this page on Github.

This post is licensed under CC BY 4.0 by the author.