mcpField
S
simulator-utils

simulator-utils

github.com/prisma-labs-dev开发349420 次安装5 周前更新
代码仓库

关于 simulator-utils

simulator-utils 是一份 iOS Simulator 命令与构建流程速查技能,面向需要在模拟器中开发和测试应用的开发者。它涵盖设备与应用操作,并说明如何调整截图尺寸以避免图像大小错误。

主要功能

  1. 01模拟器设备管理
  2. 02安装和启动应用的命令
  3. 03截图捕获与尺寸调整
  4. 04视频录制命令
  5. 05Xcode 构建与测试流程
  6. 06使用 sips 调整图像

适用场景

  1. 01启动或重置模拟器
  2. 02安装并启动构建后的应用
  3. 03捕获符合 API 尺寸要求的截图
  4. 04录制模拟器中的应用操作

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/prisma-labs-dev/apple-skills --skill simulator-utils

安装后在 Claude Code 中输入/simulator-utils确认已加载。

详细介绍

模拟器实用工具

iOS Simulator 命令快速参考。使用模拟器时请始终采用这些模式。

截图并自动调整大小(必需)

截图时务必使用此模式,以避免 API 错误:

# Single command: screenshot + resize
xcrun simctl io booted screenshot /path/to/screenshot.png && sips --resampleHeightWidthMax 1800 /path/to/screenshot.png
为什么要调整大小?
  • iPhone 17 模拟器截图的尺寸超过 2000px
  • Claude API 会拒绝多图请求中尺寸超过 2000px 的图片
  • sips --resampleHeightWidthMax 1800 可将图片尺寸控制在限制以内
调整现有截图的大小
# Single file
sips --resampleHeightWidthMax 1800 /path/to/screenshot.png

# Multiple files
sips --resampleHeightWidthMax 1800 /path/to/*.png

# Batch resize all PNGs in directory
for f in /path/to/dir/*.png; do sips --resampleHeightWidthMax 1800 "$f"; done

常用模拟器命令

设备管理
# List available simulators
xcrun simctl list devices available

# Boot specific device (prefer iPhone 17)
xcrun simctl boot "iPhone 17"

# Shutdown simulator
xcrun simctl shutdown booted

# Erase simulator (fresh state)
xcrun simctl erase "iPhone 17"

# Check booted device
xcrun simctl list devices | grep Booted
应用操作
# Install app
xcrun simctl install booted /path/to/App.app

# Launch app
xcrun simctl launch booted com.bundle.identifier

# Terminate app
xcrun simctl terminate booted com.bundle.identifier

# Uninstall app
xcrun simctl uninstall booted com.bundle.identifier
截图
# Basic screenshot (NOT recommended - use resize pattern above)
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

# Screenshot to clipboard
xcrun simctl io booted screenshot - | pbcopy
视频录制
# Start recording
xcrun simctl io booted recordVideo /path/to/video.mov

# Stop recording: Ctrl+C

构建命令

# Build for simulator
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)"

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

完整测试工作流

构建、安装、启动和截图的完整模式:

# 1. 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)
xcrun simctl terminate booted com.bundle.identifier 2>/dev/null

# 3. Install
xcrun simctl install booted "/path/to/App.app"

# 4. Launch
xcrun simctl launch booted com.bundle.identifier

# 5. Wait for app to load
sleep 2

# 6. Screenshot with resize
xcrun simctl io booted screenshot /path/to/screenshot.png && sips --resampleHeightWidthMax 1800 /path/to/screenshot.png

使用 sips 处理图像

sips(Scriptable Image Processing System)是 macOS 内置工具:

# Resize to max dimension (maintains aspect ratio)
sips --resampleHeightWidthMax 1800 image.png

# Resize to specific width
sips --resampleWidth 1000 image.png

# Resize to specific height
sips --resampleHeight 1000 image.png

# Get image dimensions
sips -g pixelWidth -g pixelHeight image.png

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

# Batch resize
sips --resampleHeightWidthMax 1800 *.png

故障排除

“No devices are booted”
xcrun simctl boot "iPhone 17"
截图尺寸过大,无法用于 API
sips --resampleHeightWidthMax 1800 /path/to/screenshot.png
应用无法启动
# Check bundle ID
xcrun simctl listapps booted | grep -A5 "CFBundleIdentifier"

# Reinstall
xcrun simctl uninstall booted com.bundle.identifier
xcrun simctl install booted /path/to/App.app
模拟器卡住
xcrun simctl shutdown all
xcrun simctl erase all
xcrun simctl boot "iPhone 17"

评论

支持 Markdown