Skip to content

XCTest simulator version of build_and_inject #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ Modify the iOS Simulator so that it has a perfect status bar, then run your app

Starting in Xcode 11, the `simctl` command line tool includes a `status_bar` option that allows you to override the appearance of the status bar in the simulator. Hopefully this will eventually supercede the need for SimulatorStatusMagic, but at the moment it still has holes that make this project continue to be relevant. In particular, `simctl status_bar` does not currently provide a way to add localized date and time strings in the status bar.

## 1) Injecting into Springboard (Required on iOS 17+)
**tl;dr** Running `build_and_inject.sh booted` will apply a default status bar to the running simulator. Replace "booted" with a simulator UDID to target a specific simulator.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

## Usage

### 1) Injecting into Springboard (Required on iOS 17+)
**tl;dr** Running `build_and_inject.sh booted` will apply a default status bar to the running simulator. Replace "booted" with a simulator UDID to target a specific simulator. Retrieve them with `xcrun simctl list devices | grep 'Booted'`

**For XCTest simulators, use `build_and_inject_test.sh booted`** - Replace "booted" with a simulator UDID to target a specific simulator. Retrieve them with `xcrun simctl --set testing list devices | grep 'Booted'`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I think this is a great addition.

We should also clarify that this is only for duplicated simulators created by using the -parallel-testing-enabled flag on xcodebuild. If you are using XCTest but not using parallel testing, this line might be misleading.


As of iOS 17, the API used by SimulatorStatusMagic is not accessible to processes other than Springboard. So, in iOS 17+ we need to inject SimulatorStatusMagic into the Springboard process itself, which we do by building it as a dynamic library, and then updating Springboard's launchd configuration to load our dynamic library.

Running `build_and_inject.sh` will do all of this for you. If you want to change anything about the values used in the status bar, you will need to update DynamicLibrary/main.m.


## 2) Using in screenshot automation UI Tests
### 2) Using in screenshot automation UI Tests (iOS 16 and lower)
- Add the swift package in xcode using the repository url (https://github.com/shinydevelopment/SimulatorStatusMagic)
- Select your UI Test target when asked what target to add it to
- Call the following in your tests:
Expand All @@ -46,7 +49,7 @@ final class YourUITests: XCTestCase {
It is recommended to **only** include `SDStatusBarManager` in your debug configuration so that the code is **never** included in release builds. When you want to apply a perfect status bar, call `[[SDStatusBarManager sharedInstance] enableOverrides]`. To restore the standard status bar, call `[[SDStatusBarManager sharedInstance] disableOverrides]`.


## 3) Using the demo app to enable/disable overrides
### 3) Using the demo app to enable/disable overrides (iOS 16 and lower)

* Clone this repository.
* Open SimulatorStatusMagic.xcodeproj with Xcode 6 (or above).
Expand Down
6 changes: 6 additions & 0 deletions build_and_inject_test.sh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of a separate script this could be a flag that is passed to build_and_inject.sh, so we don't have to maintain two largely duplicate scripts?

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cd "$(dirname "$0")"
xcodebuild -scheme "SimulatorStatusMagicDlib" -sdk iphonesimulator -derivedDataPath build

# Set testing to detect XCTest simulators
xcrun simctl --set testing spawn $1 launchctl debug system/com.apple.SpringBoard --environment DYLD_INSERT_LIBRARIES="$PWD/build/Build/Products/Debug-iphonesimulator/libSimulatorStatusMagicDlib.dylib"
xcrun simctl --set testing spawn $1 launchctl stop com.apple.SpringBoard