simulator-utils

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Simulator Utilities

模拟器实用工具

Quick reference for iOS Simulator commands. Use these patterns whenever working with simulators.
iOS Simulator 命令快速参考。在操作模拟器时请始终遵循这些使用模式。

Screenshot with Auto-Resize (REQUIRED)

自动调整尺寸的截图(必用)

ALWAYS use this pattern when taking screenshots to avoid API errors:
bash
undefined
截取截图时请始终使用该模式以避免API错误:
bash
undefined

Single command: screenshot + resize

单命令:截图 + 调整尺寸

xcrun simctl io booted screenshot /path/to/screenshot.png && sips --resampleHeightWidthMax 1800 /path/to/screenshot.png
undefined
xcrun simctl io booted screenshot /path/to/screenshot.png && sips --resampleHeightWidthMax 1800 /path/to/screenshot.png
undefined

Why Resize?

为什么需要调整尺寸?

  • iPhone 17 simulator screenshots exceed 2000px
  • Claude API rejects images >2000px in multi-image requests
  • sips --resampleHeightWidthMax 1800
    keeps images under limit
  • iPhone 17模拟器截图尺寸超过2000px
  • Claude API在多图片请求中会拒绝大于2000px的图片
  • sips --resampleHeightWidthMax 1800
    可将图片大小控制在限制以内

Resize Existing Screenshots

调整已有截图的尺寸

bash
undefined
bash
undefined

Single file

单个文件

sips --resampleHeightWidthMax 1800 /path/to/screenshot.png
sips --resampleHeightWidthMax 1800 /path/to/screenshot.png

Multiple files

多个文件

sips --resampleHeightWidthMax 1800 /path/to/*.png
sips --resampleHeightWidthMax 1800 /path/to/*.png

Batch resize all PNGs in directory

批量调整目录下所有PNG图片尺寸

for f in /path/to/dir/*.png; do sips --resampleHeightWidthMax 1800 "$f"; done

---
for f in /path/to/dir/*.png; do sips --resampleHeightWidthMax 1800 "$f"; done

---

Common Simulator Commands

常用模拟器命令

Device Management

设备管理

bash
undefined
bash
undefined

List available simulators

列出可用模拟器

xcrun simctl list devices available
xcrun simctl list devices available

Boot specific device (prefer iPhone 17)

启动指定设备(优先选择iPhone 17)

xcrun simctl boot "iPhone 17"
xcrun simctl boot "iPhone 17"

Shutdown simulator

关闭模拟器

xcrun simctl shutdown booted
xcrun simctl shutdown booted

Erase simulator (fresh state)

清除模拟器数据(恢复初始状态)

xcrun simctl erase "iPhone 17"
xcrun simctl erase "iPhone 17"

Check booted device

查看已启动的设备

xcrun simctl list devices | grep Booted
undefined
xcrun simctl list devices | grep Booted
undefined

App Operations

应用操作

bash
undefined
bash
undefined

Install app

安装应用

xcrun simctl install booted /path/to/App.app
xcrun simctl install booted /path/to/App.app

Launch app

启动应用

xcrun simctl launch booted com.bundle.identifier
xcrun simctl launch booted com.bundle.identifier

Terminate app

终止应用

xcrun simctl terminate booted com.bundle.identifier
xcrun simctl terminate booted com.bundle.identifier

Uninstall app

卸载应用

xcrun simctl uninstall booted com.bundle.identifier
undefined
xcrun simctl uninstall booted com.bundle.identifier
undefined

Screenshots

截图

bash
undefined
bash
undefined

Basic screenshot (NOT recommended - use resize pattern above)

基础截图(不推荐 - 请使用上方的调整尺寸模式)

xcrun simctl io booted screenshot /path/to/screenshot.png
xcrun simctl io booted screenshot /path/to/screenshot.png

Screenshot with resize (RECOMMENDED)

带尺寸调整的截图(推荐)

xcrun simctl io booted screenshot /path/to/screenshot.png && sips --resampleHeightWidthMax 1800 /path/to/screenshot.png
xcrun simctl io booted screenshot /path/to/screenshot.png && sips --resampleHeightWidthMax 1800 /path/to/screenshot.png

Screenshot to clipboard

截图保存到剪贴板

xcrun simctl io booted screenshot - | pbcopy
undefined
xcrun simctl io booted screenshot - | pbcopy
undefined

Video Recording

视频录制

bash
undefined
bash
undefined

Start recording

开始录制

xcrun simctl io booted recordVideo /path/to/video.mov
xcrun simctl io booted recordVideo /path/to/video.mov

Stop recording: Ctrl+C

停止录制:按下Ctrl+C


---

---

Build Commands

构建命令

bash
undefined
bash
undefined

Build for simulator

为模拟器构建

xcodebuild -scheme SCHEME -project /path/to/Project.xcodeproj -destination 'platform=iOS Simulator,name=iPhone 17' build
xcodebuild -scheme SCHEME -project /path/to/Project.xcodeproj -destination 'platform=iOS Simulator,name=iPhone 17' build

Build with output filtering (cleaner)

带输出过滤的构建(更整洁)

xcodebuild -scheme SCHEME -project /path/to/Project.xcodeproj -destination 'platform=iOS Simulator,name=iPhone 17' build 2>&1 | grep -E "(error:|warning:|BUILD)"
xcodebuild -scheme SCHEME -project /path/to/Project.xcodeproj -destination 'platform=iOS Simulator,name=iPhone 17' build 2>&1 | grep -E "(error:|warning:|BUILD)"

Find built .app path

查找构建后的.app路径

find ~/Library/Developer/Xcode/DerivedData -name ".app" -path "/Debug-iphonesimulator/*" -type d 2>/dev/null | head -1

---
find ~/Library/Developer/Xcode/DerivedData -name ".app" -path "/Debug-iphonesimulator/*" -type d 2>/dev/null | head -1

---

Full Test Workflow

完整测试工作流

Complete pattern for build, install, launch, screenshot:
bash
undefined
构建、安装、启动、截图的完整模式:
bash
undefined

1. Build

1. 构建

xcodebuild -scheme SCHEME -project /path/to/Project.xcodeproj -destination 'platform=iOS Simulator,name=iPhone 17' build 2>&1 | grep -E "(error:|BUILD)"
xcodebuild -scheme SCHEME -project /path/to/Project.xcodeproj -destination 'platform=iOS Simulator,name=iPhone 17' build 2>&1 | grep -E "(error:|BUILD)"

2. Terminate existing instance (ignore errors)

2. 终止已有实例(忽略错误)

xcrun simctl terminate booted com.bundle.identifier 2>/dev/null
xcrun simctl terminate booted com.bundle.identifier 2>/dev/null

3. Install

3. 安装

xcrun simctl install booted "/path/to/App.app"
xcrun simctl install booted "/path/to/App.app"

4. Launch

4. 启动

xcrun simctl launch booted com.bundle.identifier
xcrun simctl launch booted com.bundle.identifier

5. Wait for app to load

5. 等待应用加载

sleep 2
sleep 2

6. Screenshot with resize

6. 截图并调整尺寸

xcrun simctl io booted screenshot /path/to/screenshot.png && sips --resampleHeightWidthMax 1800 /path/to/screenshot.png

---
xcrun simctl io booted screenshot /path/to/screenshot.png && sips --resampleHeightWidthMax 1800 /path/to/screenshot.png

---

Image Manipulation with sips

使用sips进行图像处理

sips
(Scriptable Image Processing System) is macOS built-in:
bash
undefined
sips
(可脚本化图像处理系统)是macOS内置工具:
bash
undefined

Resize to max dimension (maintains aspect ratio)

调整到最大尺寸(保持宽高比)

sips --resampleHeightWidthMax 1800 image.png
sips --resampleHeightWidthMax 1800 image.png

Resize to specific width

调整到指定宽度

sips --resampleWidth 1000 image.png
sips --resampleWidth 1000 image.png

Resize to specific height

调整到指定高度

sips --resampleHeight 1000 image.png
sips --resampleHeight 1000 image.png

Get image dimensions

获取图片尺寸

sips -g pixelWidth -g pixelHeight image.png
sips -g pixelWidth -g pixelHeight image.png

Convert format

转换格式

sips -s format jpeg image.png --out image.jpg
sips -s format jpeg image.png --out image.jpg

Batch resize

批量调整尺寸

sips --resampleHeightWidthMax 1800 *.png

---
sips --resampleHeightWidthMax 1800 *.png

---

Troubleshooting

问题排查

"No devices are booted"

"No devices are booted"

bash
xcrun simctl boot "iPhone 17"
bash
xcrun simctl boot "iPhone 17"

Screenshot too large for API

截图尺寸超出API限制

bash
sips --resampleHeightWidthMax 1800 /path/to/screenshot.png
bash
sips --resampleHeightWidthMax 1800 /path/to/screenshot.png

App won't launch

应用无法启动

bash
undefined
bash
undefined

Check bundle ID

检查包ID

xcrun simctl listapps booted | grep -A5 "CFBundleIdentifier"
xcrun simctl listapps booted | grep -A5 "CFBundleIdentifier"

Reinstall

重新安装

xcrun simctl uninstall booted com.bundle.identifier xcrun simctl install booted /path/to/App.app
undefined
xcrun simctl uninstall booted com.bundle.identifier xcrun simctl install booted /path/to/App.app
undefined

Simulator stuck

模拟器卡住

bash
xcrun simctl shutdown all
xcrun simctl erase all
xcrun simctl boot "iPhone 17"
bash
xcrun simctl shutdown all
xcrun simctl erase all
xcrun simctl boot "iPhone 17"