iOS 模擬器是 Xcode 內建工具,在 Mac 上**模擬** iOS 裝置行為,讓開發者無需實機即可開發、測試、除錯 App。它是**模擬器**而非仿真器:執行 x86_64 代碼、使用 Mac 圖形堆疊渲染、不模擬 ARM 硬體細節。
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.appxcrun simctl boot "iPhone 15"Xcode → Window → Devices and Simulators → Simulators 標籤:
切換方式:滑鼠拖曳、鍵盤快捷鍵 (Cmd+左右箭頭)、Hardware 菜單。




| 功能 | 菜單路徑 | 快捷鍵 | 說明 |
|---|---|---|---|
| 旋轉裝置 | Device → Rotate Left/Right | Cmd+←/→ | 觸發介面旋轉、自動佈局更新 |
| 搖晃手勢 | Device → Shake Gesture | Cmd+Ctrl+Z | 觸發搖一搖、撤銷輸入 |
| Home 鍵 | Device → Home | Cmd+Shift+H | 返回主畫面 |
| 鎖定螢幕 | Device → Lock | Cmd+L | 模擬鎖屏、通知顯示 |
| 截圖 | File → New Screen Shot | Cmd+S | 儲存至桌面 PNG |
| 錄屏 | File → Record Screen | — | 錄製 .mov 影片 |
| GPS 位置 | Features → Location → Custom/Apple/City Run/... | — | 模擬靜態/動態位置 |
| 觸控模式 | Debug → Touch Pressure / Touch ID | — | Force Touch、指紋驗證模擬 |
| 網路狀態 | Debug → Network Link Conditioner | — | 模擬 3G/4G/Edge/離線/高延遲 |
| 記憶體警告 | Debug → Simulate Memory Warning | — | 測試 didReceiveMemoryWarning |
| 深色模式 | Features → Toggle Appearance | Cmd+Shift+A | 切換 Light/Dark Mode |
Features → Location → Custom Location → 輸入經緯度。預設為 Apple 總部 (37.785834, -122.406417)。GPX 檔案可模擬路徑移動。


File → Save Screen Shot (Cmd+S) 儲存至:**桌面** (現代 Xcode 版本),非舊版隱藏 Library 路徑。
歷史版本位置:~/Library/Developer/CoreSimulator/Devices/[UDID]/data/Media/DCIM/



# 終端機
xcrun simctl get_app_container booted com.yourcompany.yourapp
# 輸出沙盒完整路徑,可 cd 進入或 open 打開 Finder
或 Xcode → Window → Devices → 下載容器 (.xcappdata) → 右鍵顯示包內容。
# 列出所有裝置
xcrun simctl list devices
# 啟動/關閉
xcrun simctl boot "iPhone 15 Pro"
xcrun simctl shutdown "iPhone 15 Pro"
# 安裝/解除 App
xcrun simctl install booted /path/to/App.app
xcrun simctl uninstall booted com.bundle.id
# 開啟 URL (測試 Universal Links/Deep Links)
xcrun simctl openurl booted "https://example.com"
# 推送通知測試 (需 .apns 檔)
xcrun simctl push booted com.bundle.id notification.apns
# 刪除所有不可用裝置
xcrun simctl delete unavailable
iOS Simulator 是開發階段**最高效**的驗證工具,掌握 `simctl`、硬體模擬、沙盒訪問、網路抓包等進階技巧,能大幅提升開發迭代速度。但記住:**功能驗證用模擬器,效能/相機/傳感器/金鑰串/推播/支付必須真機**。