iOS simulator
screenshots
iOS development
Xcode
app testing

How to take a screenshot in the iOS Simulator (shortcut and command line)

Codemia Knowledge Hub ·

Press Command + S in the iOS Simulator to save a PNG screenshot to your desktop. For scripts and CI, run xcrun simctl io booted screenshot from the command line. In XCTest suites, XCUIScreen.main.screenshot() captures the screen so you can attach it to test results.

Keyboard shortcut: Command + S

With the Simulator in focus and your app on the screen you want:

  1. Press Command + S.
  2. The screenshot saves as a PNG file to your desktop by default.

File > Save Screenshot does the same thing. The image uses the simulated device's native resolution (for example, 1179 x 2556 for iPhone 15 Pro at 3x).

Changing where screenshots are saved

Use the defaults command to change the save location:

bash
1# Save screenshots to a custom directory
2defaults write com.apple.iphonesimulator ScreenShotSaveLocation ~/Screenshots/simulator
3
4# Verify the setting
5defaults read com.apple.iphonesimulator ScreenShotSaveLocation

Create the directory first if it does not exist:

bash
mkdir -p ~/Screenshots/simulator

If you later delete that directory, Command + S fails silently. Recreate it, or go back to the default with defaults delete com.apple.iphonesimulator ScreenShotSaveLocation.

Command line: xcrun simctl io screenshot

simctl io captures screenshots without any GUI interaction, which makes it the tool for automation:

bash
1# Save to a specific file path
2xcrun simctl io booted screenshot ~/Desktop/login-screen.png
3
4# Capture with a specific image type
5xcrun simctl io booted screenshot --type=jpeg ~/Desktop/login-screen.jpg
6
7# PNG is the default type; set it explicitly
8xcrun simctl io booted screenshot --type=png /tmp/screenshot.png

When several simulators are running, or to target a particular device, pass its UDID instead of booted:

bash
1# List running simulators
2xcrun simctl list devices | grep Booted
3
4# Capture from a specific device
5xcrun simctl io 4A2B3C4D-5E6F-7890-ABCD-EF1234567890 screenshot output.png

The command fails with a vague error if no simulator is booted, so check xcrun simctl list devices | grep Booted before scripting captures.

Capturing every booted simulator at once

This script screenshots each booted simulator, which helps when producing App Store screenshots for several device sizes:

bash
1#!/bin/bash
2OUTPUT_DIR="./screenshots/$(date +%Y%m%d_%H%M%S)"
3mkdir -p "$OUTPUT_DIR"
4
5xcrun simctl list devices | grep "Booted" | while read -r line; do
6  UDID=$(echo "$line" | grep -oE '[A-F0-9-]{36}')
7  NAME=$(echo "$line" | sed 's/ (.*//' | xargs)
8  FILENAME=$(echo "$NAME" | tr ' ' '_')
9  xcrun simctl io "$UDID" screenshot "$OUTPUT_DIR/${FILENAME}.png"
10  echo "Captured: $NAME"
11done

Screenshots inside XCTest

For automated tests, XCUIScreen captures a screenshot you can attach to the test results:

swift
1import XCTest
2
3class ScreenshotTests: XCTestCase {
4    func testLoginScreenLayout() {
5        let app = XCUIApplication()
6        app.launch()
7
8        // Navigate to the screen you want to capture
9        app.textFields["email"].tap()
10
11        // Take a screenshot
12        let screenshot = XCUIScreen.main.screenshot()
13
14        // Attach it to the test results
15        let attachment = XCTAttachment(screenshot: screenshot)
16        attachment.name = "Login Screen"
17        attachment.lifetime = .keepAlways
18        add(attachment)
19    }
20}

Attachments with .keepAlways appear in the Xcode Test Report and can be exported from the .xcresult bundle. With .deleteOnSuccess, screenshots from passing tests are discarded, so use .keepAlways when you need them for documentation or regression comparison.

To pull them out of the result bundle, use xcresulttool:

bash
1# Find the result bundle
2ls ~/Library/Developer/Xcode/DerivedData/*/Logs/Test/*.xcresult
3
4# Export all attachments
5xcrun xcresulttool export attachments --path <result-bundle>.xcresult --output-path ./attachments

Recording video instead

simctl io can also record video, which is handy for interaction flows:

bash
1# Start recording
2xcrun simctl io booted recordVideo ~/Desktop/demo.mov
3
4# Press Ctrl+C to stop recording

The video records at the device's native resolution and frame rate.

Which screenshot method to use

MethodBest forAutomatableOutput formatResolution
Command + SQuick manual capturesNoPNGDevice native
xcrun simctl io screenshotCI pipelines, scripted capturesYesPNG, JPEGDevice native
XCUIScreenshot in XCTestTest documentation, regression testingYesPNG (in xcresult)Device native
Xcode Devices windowOne-off captures during debuggingNoPNGDevice native

Screenshot resolution by device

Simulator deviceResolution (points)Resolution (pixels at scale)
iPhone SE (3rd gen)375 x 667750 x 1334 (2x)
iPhone 15393 x 8521179 x 2556 (3x)
iPhone 15 Pro Max430 x 9321290 x 2796 (3x)
iPad Pro 12.9"1024 x 13662048 x 2732 (2x)

The Simulator window scale (Window > Physical Size / Point Accurate / Pixel Accurate) does not change the saved resolution. Resizing the window to fit your screen has no effect; screenshots are always taken at the device's native pixel resolution.

App Store screenshots

App Store submissions need screenshots at specific device sizes. Combine simctl with fastlane snapshot to automate it:

bash
1# Using fastlane snapshot (after configuring Snapfile)
2fastlane snapshot
3
4# Or manually boot specific devices and capture
5xcrun simctl boot "iPhone 15 Pro"
6xcrun simctl boot "iPhone 15 Pro Max"
7xcrun simctl boot "iPad Pro (12.9-inch) (6th generation)"
8
9# Launch your app on each and capture
10for DEVICE in $(xcrun simctl list devices booted -j | jq -r '.devices[][] | select(.state=="Booted") | .udid'); do
11  xcrun simctl io "$DEVICE" screenshot "./appstore_${DEVICE}.png"
12done

Cleaning up the status bar

The Simulator's status bar shows "9:41 AM" by default (Apple's canonical time for marketing screenshots). To change what it shows, override the values with xcrun simctl status_bar:

bash
1xcrun simctl status_bar booted override \
2  --time "9:41" \
3  --batteryState charged \
4  --batteryLevel 100 \
5  --cellularMode active \
6  --cellularBars 4

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms