simulator-utils
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSimulator 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
undefinedSingle command: screenshot + resize
单命令:截图 + 调整尺寸
xcrun simctl io booted screenshot /path/to/screenshot.png && sips --resampleHeightWidthMax 1800 /path/to/screenshot.png
undefinedxcrun simctl io booted screenshot /path/to/screenshot.png && sips --resampleHeightWidthMax 1800 /path/to/screenshot.png
undefinedWhy Resize?
为什么需要调整尺寸?
- iPhone 17 simulator screenshots exceed 2000px
- Claude API rejects images >2000px in multi-image requests
- keeps images under limit
sips --resampleHeightWidthMax 1800
- iPhone 17模拟器截图尺寸超过2000px
- Claude API在多图片请求中会拒绝大于2000px的图片
- 可将图片大小控制在限制以内
sips --resampleHeightWidthMax 1800
Resize Existing Screenshots
调整已有截图的尺寸
bash
undefinedbash
undefinedSingle 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
undefinedbash
undefinedList 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
undefinedxcrun simctl list devices | grep Booted
undefinedApp Operations
应用操作
bash
undefinedbash
undefinedInstall 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
undefinedxcrun simctl uninstall booted com.bundle.identifier
undefinedScreenshots
截图
bash
undefinedbash
undefinedBasic 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
undefinedxcrun simctl io booted screenshot - | pbcopy
undefinedVideo Recording
视频录制
bash
undefinedbash
undefinedStart 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
undefinedbash
undefinedBuild 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
undefined1. 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进行图像处理
sipsbash
undefinedsipsbash
undefinedResize 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.pngbash
sips --resampleHeightWidthMax 1800 /path/to/screenshot.pngApp won't launch
应用无法启动
bash
undefinedbash
undefinedCheck 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
undefinedxcrun simctl uninstall booted com.bundle.identifier
xcrun simctl install booted /path/to/App.app
undefinedSimulator 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"