移动/游戏
在 macOS + Xcode 下操作 iOS…
适用于在 macOS + Xcode 环境中对 iOS Simulator 执行截图、图片缩放、设备/应用管理、构建和完整测试流程。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 38/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 60/100 ×0.15
适用场景
在 macOS + Xcode 下操作 特定
解决思路
- 截图时始终使用一条命令完成截图与缩放:`xcrun simctl io booted screenshot /path/to/screenshot.png && sips --resampleHeightWidthMax 1800 /path/to/screenshot.png`,避免 API 错误。
- 用 `sips --resampleHeightWidthMax 1800` 将图片最大边限制在 1800px:iPhone 17 模拟器截图会超过 2000px,Claude API 在多图请求中拒绝 >2000px 图片,因此该参数可让图片低于限制。
- 缩放单个已有截图:`sips --resampleHeightWidthMax 1800 /path/to/screenshot.png`。
- 缩放多个指定文件:`sips --resampleHeightWidthMax 1800 /path/to/*.png`。
- 批量缩放目录下所有 PNG:`for f in /path/to/dir/*.png; do sips --resampleHeightWidthMax 1800 "$f"; done`。
- 列出可用模拟器:`xcrun simctl list devices available`。
- 启动指定设备(优先 iPhone 17):`xcrun simctl boot "iPhone 17"`。
- 关闭已启动模拟器:`xcrun simctl shutdown booted`。
- 抹掉模拟器以恢复全新状态:`xcrun simctl erase "iPhone 17"`。
- 检查已启动设备:`xcrun simctl list devices | grep Booted`。
- 安装 App:`xcrun simctl install booted /path/to/App.app`。
- 启动 App:`xcrun simctl launch booted com.bundle.identifier`。
- 终止 App:`xcrun simctl terminate booted com.bundle.identifier`。
- 卸载 App:`xcrun simctl uninstall booted com.bundle.identifier`。
- 基础截图(不推荐,需配合缩放):`xcrun simctl io booted screenshot /path/to/screenshot.png`。
- 推荐截图并缩放:`xcrun simctl io booted screenshot /path/to/screenshot.png && sips --resampleHeightWidthMax 1800 /path/to/screenshot.png`。
- 截图到剪贴板:`xcrun simctl io booted screenshot - | pbcopy`。
- 开始录屏:`xcrun simctl io booted recordVideo /path/to/video.mov`。
- 停止录屏:按 Ctrl+C。
- 为模拟器构建:`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 2>&1 | grep -E "(error:|warning:|BUILD)"`。
- 查找构建出的 .app 路径:`find ~/Library/Developer/Xcode/DerivedData -name "*.app" -path "*/Debug-iphonesimulator/*" -type d 2>/dev/null | head -1`。
- 完整测试流程第 1 步构建并过滤:`xcodebuild -scheme SCHEME -project /path/to/Project.xcodeproj -destination 'platform=iOS Simulator,name=iPhone 17' build 2>&1 | grep -E "(error:|BUILD)"`。
- 完整测试流程第 2 步终止已有实例并忽略错误:`xcrun simctl terminate booted com.bundle.identifier 2>/dev/null`。
- 完整测试流程第 3 步安装:`xcrun simctl install booted "/path/to/App.app"`。
- 完整测试流程第 4 步启动:`xcrun simctl launch booted com.bundle.identifier`。
- 完整测试流程第 5 步等待 App 加载:`sleep 2`。
- 完整测试流程第 6 步截图并缩放:`xcrun simctl io booted screenshot /path/to/screenshot.png && sips --resampleHeightWidthMax 1800 /path/to/screenshot.png`。
- 用 sips 按最大边缩放并保持宽高比:`sips --resampleHeightWidthMax 1800 image.png`。
- 用 sips 缩放到指定宽度:`sips --resampleWidth 1000 image.png`。
- 用 sips 缩放到指定高度:`sips --resampleHeight 1000 image.png`。
- 用 sips 获取图片尺寸:`sips -g pixelWidth -g pixelHeight image.png`。
- 用 sips 转换格式:`sips -s format jpeg image.png --out image.jpg`。
- 用 sips 批量缩放:`sips --resampleHeightWidthMax 1800 *.png`。
- 遇到 “No devices are booted” 时启动模拟器:`xcrun simctl boot "iPhone 17"`。
- 遇到截图对 API 太大时缩放:`sips --resampleHeightWidthMax 1800 /path/to/screenshot.png`。
- App 无法启动时检查 bundle ID:`xcrun simctl listapps booted | grep -A5 "CFBundleIdentifier"`。
- App 无法启动时重新安装的第一步:卸载:`xcrun simctl uninstall booted com.bundle.identifier`。
- App 无法启动时重新安装的第二步:安装:`xcrun simctl install booted /path/to/App.app`。
- 模拟器卡死时关闭全部:`xcrun simctl shutdown all`。
- 模拟器卡死时抹掉全部:`xcrun simctl erase all`。
- 模拟器卡死后重新启动:`xcrun simctl boot "iPhone 17"`。
适用边界 · 注意事项
- 非 macOS 环境或未安装 Xcode/iOS Simulator 时无法执行这些命令。
- 非 iOS 模拟器或非 Xcode 项目时不需要这些命令。
- 不涉及截图上传给有 2000px 限制的多图 API 时,不必强制缩放截图。