Skip to content

Control a real USB-connected iPhone from Linux (no Mac, no paid developer account) and expose it to AI agents as MCP tools

支持 macOS:短暂断开后按 usbmuxd 编号重连、doctor 支持 macOS、新增 macOS 使用指南 (#14)

Qinghe Li0f4f756f293e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b447b55..6e3b2c2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,12 +6,18 @@ All notable changes to this project are documented here. The format is based on
## [Unreleased]
+### Added
+
+- macOS (Apple Silicon) support: build from source and run as a regular user with the system usbmuxd, no Xcode needed. Verified on macOS 26.6.2 with an iPhone 15 Pro Max (iOS 27.0.1), including alongside Finder. CI builds and tests on macOS. See the new macOS guide.
+
### Changed
- MCP tool descriptions now say when to use each tool instead of its siblings, what it returns and how it behaves (cold launch vs. resume, force-quit, swipe inertia), every parameter has a description, and every tool carries MCP annotations (title, read-only, destructive, idempotent). Tool names, parameters and results are unchanged.
### Fixed
+- The daemon no longer gets stuck on "bad device" after the phone disconnects for a few seconds (unplugging, USB-C power renegotiation): it now notices that usbmuxd gave the phone a new device number and reconnects. This affected setups using the system usbmuxd (macOS, Linux source installs); the Docker image restarts its own usbmuxd and already recovered.
+- `doctor` on macOS no longer reports "no Apple device on USB" while the phone is connected, and its fix hints use `launchctl` instead of `systemctl`.
- `home` and `lock` did nothing on an iPhone 12 mini (iOS 26.4.1) while reporting success, and auto-unlock could not wake a dark screen. Home is now pressed as an IOHID AC Home event, falling back to the XCTest button if the home screen doesn't come up; lock presses the power key over IOHID, falling back to WebDriverAgent's lock. Auto-unlock alternates the two ways of waking the screen.
- When auto-unlock can't bring up the passcode keypad, the message now mentions StandBy (a phone charging on its side), which hides the keypad.
diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md
index 84607de..1899c30 100644
--- a/CHANGELOG.zh-CN.md
+++ b/CHANGELOG.zh-CN.md
@@ -6,12 +6,18 @@
## [Unreleased]
+### 新增
+
+- 支持 macOS(Apple Silicon):从源码编译,以普通用户运行,用系统自带的 usbmuxd,不需要 Xcode。已在 macOS 26.6.2 + iPhone 15 Pro Max(iOS 27.0.1)上验证,开着 Finder 也正常。CI 增加 macOS 编译和测试。新增 macOS 使用指南。
+
### 变更
- MCP 工具描述补充了何时用这个工具而不是相近的工具、返回什么、具体行为(冷启动还是切回前台、强制结束、滑动惯性),每个参数都有说明,每个工具都带 MCP 注解(标题、只读、破坏性、幂等)。工具名、参数和返回结果不变。
### 修复
+- 手机断开几秒又接上(拔插、USB-C 供电重新协商)后,守护进程不再卡在「bad device」:发现 usbmuxd 换了设备编号就重新连接。受影响的是用系统 usbmuxd 的部署(macOS、Linux 从源码运行);Docker 镜像自己重启 usbmuxd,原来就能恢复。
+- macOS 上 `doctor` 不再在手机已连接时报「USB 上没有 Apple 设备」,修复提示改用 `launchctl` 而不是 `systemctl`。
- iPhone 12 mini(iOS 26.4.1)上 `home`、`lock` 报成功但没有效果,自动解锁也点不亮熄灭的屏幕。Home 改为发 IOHID 的 AC Home 事件,没回到主屏再用 XCTest 的按键补一次;锁屏改为经 IOHID 按电源键,没锁上再用 WebDriverAgent 的锁屏。自动解锁轮流用这两种方式唤醒屏幕。
- 自动解锁调不出密码键盘时,提示里说明待机显示(手机横放充电时出现)会挡住键盘。
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 6d0b6db..ca7705e 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -42,6 +42,8 @@ python3 -m venv .venv && .venv/bin/pip install -r tests/device/requirements.txt
.venv/bin/python tests/device/run.py '[["iphone_launch_app", {"app": "设置"}], ["iphone_screenshot", {}]]'
```
+On macOS, the full checklist (setup, `debug` checks, coexistence with Finder, reconnect) is in [docs/dev/macos-verification.md](docs/dev/macos-verification.md).
+
It prints every result with its wall time and saves screenshots to `./shots`. Set `MCP_CMD` for a source install (for example `MCP_CMD="iphone-control mcp"`). Please mention in the pull request what you ran on which device and iOS version.
Notes:
diff --git a/README.md b/README.md
index ef29abf..e34b16a 100644
--- a/README.md
+++ b/README.md
@@ -12,13 +12,14 @@
<h3 align="center">iphone-control</h3>
<p align="center">
- Let an AI agent operate a real iPhone plugged into a Linux machine — one Rust binary, no Mac, no paid developer account, no jailbreak.
+ Let an AI agent operate a real iPhone plugged into a Linux machine or a Mac — one Rust binary, no Xcode, no paid developer account, no jailbreak.
</p>
<p align="center">
<a href="https://github.com/Derrors/iphone-control/releases/latest"><img src="https://img.shields.io/github/v/release/Derrors/iphone-control?style=flat-square" alt="Release"></a>
<a href="https://github.com/Derrors/iphone-control/pkgs/container/iphone-control"><img src="https://img.shields.io/badge/ghcr.io-derrors%2Fiphone--control-2496ED?style=flat-square&logo=docker&logoColor=white" alt="Docker"></a>
<img src="https://img.shields.io/badge/iOS-17%2B-black?style=flat-square&logo=apple" alt="iOS">
+ <img src="https://img.shields.io/badge/platform-Linux%20%7C%20macOS-555?style=flat-square" alt="Platform: Linux | macOS">
<img src="https://img.shields.io/badge/MCP-15%20tools-8A2BE2?style=flat-square" alt="MCP">
<a href="Cargo.toml"><img src="https://img.shields.io/badge/Rust-1.88%2B-CE422B?style=flat-square&logo=rust&logoColor=white" alt="Rust"></a>
<a href="https://github.com/Derrors/iphone-control/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/Derrors/iphone-control/ci.yml?branch=main&style=flat-square&label=CI" alt="CI"></a>
@@ -37,13 +38,13 @@
</div>
> [!NOTE]
-> Early release (0.x), tested on an **iPhone 15 Pro Max (iOS 27.0.1)**. Other models and iOS 17+ should work but are untested — reports are welcome. The CLI, `doctor` output and MCP tool results are currently in Simplified Chinese; agents handle this fine.
+> Early release (0.x). Verified with an **iPhone 15 Pro Max (iOS 27.0.1)** on Linux and macOS (Apple Silicon), and an **iPhone 12 mini (iOS 26.4.1)** on Linux. Other models and iOS 17+ should work but are untested — reports are welcome. The CLI, `doctor` output and MCP tool results are currently in Simplified Chinese; agents handle this fine.
## Overview
AI agents can drive browsers and desktops, but a real iPhone is harder: Apple's automation tools need a Mac and Xcode, and the open-source alternatives come as separate pieces that each need their own setup, signing and babysitting.
-iphone-control does it all in **one Rust binary** on Linux, built on [idevice](https://github.com/jkcoxson/idevice), [Impactor](https://github.com/claration/impactor) and [WebDriverAgent](https://github.com/appium/WebDriverAgent). A long-running daemon owns the phone — tunnel, HID session, WebDriverAgent session — and exposes it to Claude Code or any MCP client. It succeeds [iphone-control-toolkit](https://github.com/Derrors/iphone-control-toolkit) and keeps its MCP tools compatible.
+iphone-control does it all in **one Rust binary** on Linux or macOS, built on [idevice](https://github.com/jkcoxson/idevice), [Impactor](https://github.com/claration/impactor) and [WebDriverAgent](https://github.com/appium/WebDriverAgent). A long-running daemon owns the phone — tunnel, HID session, WebDriverAgent session — and exposes it to Claude Code or any MCP client. It succeeds [iphone-control-toolkit](https://github.com/Derrors/iphone-control-toolkit) and keeps its MCP tools compatible.
<p align="center">
<picture>
@@ -57,7 +58,7 @@ iphone-control does it all in **one Rust binary** on Linux, built on [idevice](h
- **See and touch the screen**: screenshots with region zoom, tap, swipe, long-press, text input (including Chinese), hardware buttons
- **Work with UI elements**: read the element tree, tap by text (on a part not covered by floating bars or the keyboard), launch and close apps, open URLs, wait for text to appear
- **Fewer round trips**: any action can return the resulting screen once it has settled, flagging pages still loading and blocking alerts; `iphone_batch` runs up to 20 steps in one call
-- **Automatic fallback**: when WebDriverAgent is down, screenshots, taps, swipes and keys switch to Apple's CoreDevice HID service
+- **Automatic fallback**: when WebDriverAgent is down, screenshots, taps, swipes and keys switch to Apple's CoreDevice HID service (iOS 27+)
- **Runs unattended**: recovers from replugging, phone reboots and WebDriverAgent crashes; re-signs WebDriverAgent with a free Apple ID before the 7-day profile expires
- **Alerts**: Telegram or Bark notifications when re-signing fails, the Apple ID session expires, the phone goes offline, or a passcode is needed after a reboot
- **Optional auto-unlock**: every passcode digit is verified, and a wrong passcode disables auto-unlock after one attempt
@@ -65,7 +66,7 @@ iphone-control does it all in **one Rust binary** on Linux, built on [idevice](h
## Quick Start
-You need a Linux host (x86_64 or arm64) with Docker (Compose v2), an iPhone on iOS 17+ connected by a **data** USB cable, and a free Apple ID (use a dedicated one, not your main account).
+On Linux you need a host (x86_64 or arm64) with Docker (Compose v2), an iPhone on iOS 17+ connected by a **data** USB cable, and a free Apple ID (use a dedicated one, not your main account).
```bash
git clone https://github.com/Derrors/iphone-control.git
@@ -91,6 +92,21 @@ Open a new Claude Code session and ask, for example:
You can also skip both the clone and the build: in a new directory, write a `compose.yaml` that uses the prebuilt image `ghcr.io/derrors/iphone-control:latest` and run `docker compose up -d` — see [Docker](https://derrors.github.io/iphone-control/en/deploy/docker#just-a-compose-file) for the full example. If you already cloned the repository, set `IMAGE=ghcr.io/derrors/iphone-control:latest` in `.env` and run `docker compose pull && docker compose up -d --no-build`. Without Docker, use a [prebuilt binary or build from source](https://derrors.github.io/iphone-control/en/deploy/source) and run it as a systemd user service.
+### macOS
+
+Docker on a Mac can't pass USB devices through to containers, so on a Mac (Apple Silicon; Xcode not needed) build the binary and run it directly, as your regular user. You need the Xcode Command Line Tools (`xcode-select --install`) and Rust 1.88+ ([rustup](https://rustup.rs)):
+
+```bash
+git clone https://github.com/Derrors/iphone-control.git
+cd iphone-control
+cargo install --path apps/iphone-control --locked # installs ~/.cargo/bin/iphone-control
+iphone-control daemon # keep this terminal open
+iphone-control setup # in a second terminal
+iphone-control mcp-config # prints the `claude mcp add` command to run
+```
+
+Set the phone's charging limit to 100% (*Settings → Battery → Charging*): with the 80% limit, USB drops about once a minute. Configuration, keeping it running and the known differences are in the [macOS guide](https://derrors.github.io/iphone-control/en/deploy/macos).
+
## MCP Tools
| Tool | Description |
@@ -111,7 +127,7 @@ Action tools accept `then: "elements" | "screenshot"` to return the screen after
## Everyday Commands
-Run them as `docker exec -it iphone-control iphone-control <command>`, or directly for a source install.
+Run them as `docker exec -it iphone-control iphone-control <command>`, or directly for a source install and on macOS.
| Command | What it does |
| --- | --- |
@@ -132,7 +148,7 @@ Upgrade with `git pull && docker compose up -d --build` (or `docker compose pull
| --- | --- |
| Guide | [What is it](https://derrors.github.io/iphone-control/en/guide/what-is-iphone-control) · [Getting started](https://derrors.github.io/iphone-control/en/guide/getting-started) · [AI clients](https://derrors.github.io/iphone-control/en/guide/mcp-clients) · [Tools](https://derrors.github.io/iphone-control/en/guide/tools) |
| Usage | [Configuration](https://derrors.github.io/iphone-control/en/guide/configuration) · [Notifications](https://derrors.github.io/iphone-control/en/guide/notifications) · [Auto-unlock](https://derrors.github.io/iphone-control/en/guide/auto-unlock) |
-| Deployment | [Docker](https://derrors.github.io/iphone-control/en/deploy/docker) · [Source / binary](https://derrors.github.io/iphone-control/en/deploy/source) · [Data and backups](https://derrors.github.io/iphone-control/en/deploy/backup) |
+| Deployment | [Docker](https://derrors.github.io/iphone-control/en/deploy/docker) · [Source / binary](https://derrors.github.io/iphone-control/en/deploy/source) · [macOS](https://derrors.github.io/iphone-control/en/deploy/macos) · [Data and backups](https://derrors.github.io/iphone-control/en/deploy/backup) |
| Problems | [FAQ](https://derrors.github.io/iphone-control/en/troubleshoot/faq) · [Troubleshooting](docs/troubleshooting.md) · [Issues](https://github.com/Derrors/iphone-control/issues) |
| Security | [SECURITY.md](SECURITY.md): what is stored, who can reach it, reporting vulnerabilities |
| Development | [Contributing](CONTRIBUTING.md) · [Architecture](docs/architecture.md) · [Decisions](docs/decisions.md) · [Changelog](CHANGELOG.md) |
@@ -147,6 +163,8 @@ The architecture and design documents are in Chinese for now.
- After the phone reboots, you must unlock it and enter the passcode once to allow UI automation — iOS requires this
- Apple ID logins use a public third-party anisette server by default; set `ICTL_ANISETTE_URL` to use your own
- The container runs as root: it needs the USB device nodes and must restart usbmuxd after replugging
+- The HID fallback needs iOS 27 or later; on older iOS everything goes through WebDriverAgent
+- On macOS: build from source (no prebuilt binary yet), run the daemon in a terminal (no launchd service yet), no Docker (no USB passthrough); data lives in `~/.local/share/iphone-control`. Intel Macs are untested
> [!WARNING]
> This tool can fully control your phone. An agent may tap payment, delete or send buttons — keep tool-call confirmation on in your MCP client. Not affiliated with Apple; use it only with devices and accounts you own. Read [SECURITY.md](SECURITY.md) before enabling auto-unlock.
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 9e7bbd1..a48d849 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -12,13 +12,14 @@
<h3 align="center">iphone-control</h3>
<p align="center">
- 让 AI agent 操作一台接在 Linux 上的真实 iPhone:一个 Rust 二进制,不需要 Mac,不需要付费开发者账号,不越狱。
+ 让 AI agent 操作一台接在 Linux 或 Mac 上的真实 iPhone:一个 Rust 二进制,不需要 Xcode,不需要付费开发者账号,不越狱。
</p>
<p align="center">
<a href="https://github.com/Derrors/iphone-control/releases/latest"><img src="https://img.shields.io/github/v/release/Derrors/iphone-control?style=flat-square" alt="Release"></a>
<a href="https://github.com/Derrors/iphone-control/pkgs/container/iphone-control"><img src="https://img.shields.io/badge/ghcr.io-derrors%2Fiphone--control-2496ED?style=flat-square&logo=docker&logoColor=white" alt="Docker"></a>
<img src="https://img.shields.io/badge/iOS-17%2B-black?style=flat-square&logo=apple" alt="iOS">
+ <img src="https://img.shields.io/badge/platform-Linux%20%7C%20macOS-555?style=flat-square" alt="平台:Linux | macOS">
<img src="https://img.shields.io/badge/MCP-15%20tools-8A2BE2?style=flat-square" alt="MCP">
<a href="Cargo.toml"><img src="https://img.shields.io/badge/Rust-1.88%2B-CE422B?style=flat-square&logo=rust&logoColor=white" alt="Rust"></a>
<a href="https://github.com/Derrors/iphone-control/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/Derrors/iphone-control/ci.yml?branch=main&style=flat-square&label=CI" alt="CI"></a>
@@ -37,13 +38,13 @@
</div>
> [!NOTE]
-> 早期版本(0.x),在 **iPhone 15 Pro Max(iOS 27.0.1)** 上完整测试过。其他机型和 iOS 17 以上应该也能用,但还没测过,欢迎反馈。
+> 早期版本(0.x)。在 Linux 和 macOS(Apple Silicon)上用 **iPhone 15 Pro Max(iOS 27.0.1)** 完整验证过,在 Linux 上用 **iPhone 12 mini(iOS 26.4.1)** 验证过。其他机型和 iOS 17 以上应该也能用,但还没测过,欢迎反馈。
## 简介
AI agent 已经能操作浏览器和电脑桌面,但真实的 iPhone 难得多:苹果的自动化工具需要 Mac 和 Xcode,开源替代品又是零散的几块,每一块都要单独安装、签名、看护。
-iphone-control 在 Linux 上用**一个 Rust 二进制**把这些事都做了,基于 [idevice](https://github.com/jkcoxson/idevice)、[Impactor](https://github.com/claration/impactor) 和 [WebDriverAgent](https://github.com/appium/WebDriverAgent)。一个常驻守护进程独占手机(隧道、HID 会话、WebDriverAgent 会话常驻复用),把它交给 Claude Code 或任何 MCP 客户端。它是 [iphone-control-toolkit](https://github.com/Derrors/iphone-control-toolkit) 的继任者,MCP 工具保持兼容。
+iphone-control 在 Linux 或 macOS 上用**一个 Rust 二进制**把这些事都做了,基于 [idevice](https://github.com/jkcoxson/idevice)、[Impactor](https://github.com/claration/impactor) 和 [WebDriverAgent](https://github.com/appium/WebDriverAgent)。一个常驻守护进程独占手机(隧道、HID 会话、WebDriverAgent 会话常驻复用),把它交给 Claude Code 或任何 MCP 客户端。它是 [iphone-control-toolkit](https://github.com/Derrors/iphone-control-toolkit) 的继任者,MCP 工具保持兼容。
<p align="center">
<picture>
@@ -57,7 +58,7 @@ iphone-control 在 Linux 上用**一个 Rust 二进制**把这些事都做了,
- **看屏幕、点屏幕**:截图(可放大某块区域)、点击、滑动、长按、输入文字(支持中文)、硬件按键
- **按界面元素操作**:读元素树、按文字点击(自动避开悬浮栏、键盘挡住的部分)、启动和结束 App、打开链接、等某段文字出现
- **省往返**:任何操作都可以等界面稳定后顺带返回操作后的样子,并提示页面是否还在加载、有没有弹窗挡着;`iphone_batch` 一次执行最多 20 步
-- **自动后备**:WebDriverAgent 不可用时,截图、点击、滑动、按键改走苹果的 CoreDevice HID 服务
+- **自动后备**:WebDriverAgent 不可用时,截图、点击、滑动、按键改走苹果的 CoreDevice HID 服务(iOS 27 起)
- **无人值守**:拔插、手机重启、WebDriverAgent 崩溃后自动恢复;用免费 Apple ID 签名,7 天描述文件过期前自动重签
- **告警通知**:重签失败、Apple ID 会话失效、手机离线、重启后需要输密码时,经 Telegram 或 Bark 推送
- **可选的自动解锁**:每输一位都核对,密码错了只试一次就停用
@@ -65,7 +66,7 @@ iphone-control 在 Linux 上用**一个 Rust 二进制**把这些事都做了,
## 快速开始
-需要一台装了 Docker(Compose v2)的 Linux 主机(x86_64 或 arm64)、一部 iOS 17 以上的 iPhone 和能**传数据**的线,以及一个免费 Apple ID(建议专门注册一个,不要用主账号)。
+在 Linux 上,需要一台装了 Docker(Compose v2)的主机(x86_64 或 arm64)、一部 iOS 17 以上的 iPhone 和能**传数据**的线,以及一个免费 Apple ID(建议专门注册一个,不要用主账号)。
```bash
git clone https://github.com/Derrors/iphone-control.git
@@ -91,6 +92,21 @@ claude mcp add iphone -s user -- docker exec -i iphone-control iphone-control mc
也可以不克隆仓库、不自己构建:新建一个目录,写一个使用预构建镜像 `ghcr.io/derrors/iphone-control:latest` 的 `compose.yaml`,然后 `docker compose up -d`,完整示例见 [Docker 部署](https://derrors.github.io/iphone-control/deploy/docker#只写一个-compose-文件)。已经克隆了仓库的话,在 `.env` 里设 `IMAGE=ghcr.io/derrors/iphone-control:latest`,然后 `docker compose pull && docker compose up -d --no-build`。不用 Docker 的话,可以用[预编译二进制或从源码编译](https://derrors.github.io/iphone-control/deploy/source),以 systemd 用户服务运行。
+### macOS
+
+Mac 上的 Docker 不能把 USB 设备交给容器,所以在 Mac(Apple Silicon,不需要 Xcode)上要编译出二进制,以普通用户直接运行。需要 Xcode 命令行工具(`xcode-select --install`)和 Rust 1.88+([rustup](https://rustup.rs)):
+
+```bash
+git clone https://github.com/Derrors/iphone-control.git
+cd iphone-control
+cargo install --path apps/iphone-control --locked # 装到 ~/.cargo/bin/iphone-control
+iphone-control daemon # 这个终端保持开着
+iphone-control setup # 在另一个终端运行
+iphone-control mcp-config # 打印 `claude mcp add` 命令,复制运行
+```
+
+把手机的充电上限改成 100%(设置 → 电池 → 充电):开着「80% 上限」时 USB 大约每分钟断开一次。配置、保持运行和已知差异见 [macOS 指南](https://derrors.github.io/iphone-control/deploy/macos)。
+
## MCP 工具
| 工具 | 作用 |
@@ -111,7 +127,7 @@ claude mcp add iphone -s user -- docker exec -i iphone-control iphone-control mc
## 常用命令
-用 `docker exec -it iphone-control iphone-control <命令>` 运行;从源码运行时直接调用。
+用 `docker exec -it iphone-control iphone-control <命令>` 运行;从源码运行和在 macOS 上直接调用。
| 命令 | 作用 |
| --- | --- |
@@ -132,7 +148,7 @@ claude mcp add iphone -s user -- docker exec -i iphone-control iphone-control mc
| --- | --- |
| 入门 | [什么是 iphone-control](https://derrors.github.io/iphone-control/guide/what-is-iphone-control) · [快速开始](https://derrors.github.io/iphone-control/guide/getting-started) · [接入 AI 客户端](https://derrors.github.io/iphone-control/guide/mcp-clients) · [工具一览](https://derrors.github.io/iphone-control/guide/tools) |
| 使用 | [配置](https://derrors.github.io/iphone-control/guide/configuration) · [通知](https://derrors.github.io/iphone-control/guide/notifications) · [自动解锁](https://derrors.github.io/iphone-control/guide/auto-unlock) |
-| 安装 | [Docker](https://derrors.github.io/iphone-control/deploy/docker) · [从源码 / 二进制](https://derrors.github.io/iphone-control/deploy/source) · [数据与备份](https://derrors.github.io/iphone-control/deploy/backup) |
+| 安装 | [Docker](https://derrors.github.io/iphone-control/deploy/docker) · [从源码 / 二进制](https://derrors.github.io/iphone-control/deploy/source) · [macOS](https://derrors.github.io/iphone-control/deploy/macos) · [数据与备份](https://derrors.github.io/iphone-control/deploy/backup) |
| 问题 | [常见问题](https://derrors.github.io/iphone-control/troubleshoot/faq) · [排错(英文)](docs/troubleshooting.md) · [Issues](https://github.com/Derrors/iphone-control/issues) |
| 安全 | [SECURITY.md](SECURITY.md):存了什么、谁能访问、怎么报告漏洞 |
| 开发 | [贡献指南](CONTRIBUTING.md) · [架构](docs/architecture.md) · [关键取舍](docs/decisions.md) · [更新日志](CHANGELOG.zh-CN.md) |
@@ -145,6 +161,8 @@ claude mcp add iphone -s user -- docker exec -i iphone-control iphone-control mc
- 手机重启后,要人工解锁一次,并输一次密码允许 UI 自动化,这是 iOS 的要求
- 登录 Apple ID 默认用公共的第三方 anisette 服务;可设 `ICTL_ANISETTE_URL` 换成自建服务
- 容器以 root 运行:要访问 USB 设备节点,拔插后还要能重启 usbmuxd
+- HID 后备路线要 iOS 27 及以上;更早的 iOS 全部经 WebDriverAgent 操作
+- macOS 上:只能从源码编译(还没有预编译二进制),守护进程在终端里前台运行(还没有 launchd 配置),不能用 Docker(没有 USB 直通);数据在 `~/.local/share/iphone-control`。Intel Mac 还没测过
> [!WARNING]
> 这个工具能完全控制你的手机,agent 可能点到付款、删除、发送这类按钮,请在 MCP 客户端里保持工具调用确认。本项目与 Apple 无关;只在你自己的设备和账号上使用。开启自动解锁前请先读 [SECURITY.md](SECURITY.md)。
diff --git a/SECURITY.md b/SECURITY.md
index 620d11a..b1274cf 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -17,7 +17,7 @@ iphone-control is, by design, a remote control for a phone. Anyone who can talk
| Apple ID session tokens, development signing key and certificate | `account/` in the data directory (0700, key 0600) | Whoever can read the data directory. The Apple ID password itself is never stored |
| Pairing records | `lockdown/` in the data directory (container) or the system's `/var/lib/lockdown` | Root on the host. A pairing record lets its holder talk to the phone over USB without another *Trust* prompt |
| Lock-screen passcode | `secrets/passcode` in the data directory (0600), **plain text**, only if you ran `passcode set` | Whoever can read the data directory |
-| Notification credentials (Bark key, Telegram token) | `.env` or the systemd environment file | Whoever can read that file |
+| Notification credentials (Bark key, Telegram token) | `.env` or `~/.config/iphone-control/env` | Whoever can read that file |
The data directory is `./data` next to `compose.yaml` for the container (root-owned, mode 0700) and `~/.local/share/iphone-control` for a source install.
diff --git a/apps/iphone-control/src/main.rs b/apps/iphone-control/src/main.rs
index 3728c7a..2cd6a70 100644
--- a/apps/iphone-control/src/main.rs
+++ b/apps/iphone-control/src/main.rs
@@ -14,7 +14,7 @@ use ictl_daemon::protocol::{self, Request, Response};
mod debug;
#[derive(Parser)]
-#[command(name = "iphone-control", version, about = "在 Linux 上控制 iPhone,并提供 MCP 工具")]
+#[command(name = "iphone-control", version, about = "在 Linux 或 macOS 上控制 iPhone,并提供 MCP 工具")]
struct Cli {
/// 数据根目录(账号、描述文件、日志等)。默认:root 是 /var/lib/iphone-control,普通用户是 ~/.local/share/iphone-control
#[arg(long, env = "ICTL_DATA_DIR", default_value_os_t = protocol::default_data_dir())]
diff --git a/crates/ictl-daemon/src/doctor.rs b/crates/ictl-daemon/src/doctor.rs
index 7abb7db..116798b 100644
--- a/crates/ictl-daemon/src/doctor.rs
+++ b/crates/ictl-daemon/src/doctor.rs
@@ -1,10 +1,8 @@
//! `iphone-control doctor`:逐层诊断,每项失败都给出修复办法。
-use std::path::Path;
use std::time::Duration;
use crate::core::{Daemon, Inner};
-use crate::supervise::SYSFS_USB;
impl Daemon {
pub(crate) async fn doctor(&self, g: &mut Inner) -> String {
@@ -19,6 +17,8 @@ impl Daemon {
"❌ 连不上 usbmuxd:{e}\n → {}",
if self.cfg.manage_usbmuxd {
"由守护进程自动拉起,看数据目录 logs/usbmuxd.log;宿主机已有 usbmuxd 服务时设 ICTL_MANAGE_USBMUXD=0"
+ } else if cfg!(target_os = "macos") {
+ "macOS 自带 usbmuxd,应一直在运行:sudo launchctl kickstart -k system/com.apple.usbmuxd"
} else {
"用的是系统的 usbmuxd 服务(插上手机时由 udev 拉起):确认已安装 usbmuxd、手机已插好"
}
@@ -26,11 +26,14 @@ impl Daemon {
fails += 1;
}
}
- if ictl_device::apple_usb_present(Path::new(SYSFS_USB)) {
- out.push("✅ USB 上有 Apple 设备".into());
- } else {
- out.push("❌ USB 上没有 Apple 设备\n → 插好数据线;用 USB-C 转接头的话换一根试试".into());
- fails += 1;
+ // 判断不了(不是 Linux/macOS)就不报,免得误报「没有设备」
+ match ictl_device::host_apple_usb_present().await {
+ Some(true) => out.push("✅ USB 上有 Apple 设备".into()),
+ Some(false) => {
+ out.push("❌ USB 上没有 Apple 设备\n → 插好数据线;用 USB-C 转接头的话换一根试试".into());
+ fails += 1;
+ }
+ None => {}
}
match (&g.device, &g.info) {
(Some(d), info) => {
@@ -47,6 +50,8 @@ impl Daemon {
out.push(
if self.cfg.manage_usbmuxd {
"❌ 守护进程看不到手机\n → 等 30 秒,会自动重启 usbmuxd;仍不行就重启容器(或守护进程)"
+ } else if cfg!(target_os = "macos") {
+ "❌ 守护进程看不到手机\n → 重新插拔数据线;仍不行就 sudo launchctl kickstart -k system/com.apple.usbmuxd"
} else {
"❌ 守护进程看不到手机\n → 重新插拔数据线;仍不行就 sudo systemctl restart usbmuxd"
}
diff --git a/crates/ictl-daemon/src/supervise.rs b/crates/ictl-daemon/src/supervise.rs
index 127c859..7d927fc 100644
--- a/crates/ictl-daemon/src/supervise.rs
+++ b/crates/ictl-daemon/src/supervise.rs
@@ -4,7 +4,7 @@ use std::path::Path;
use std::sync::Arc;
use std::time::{Duration, Instant, UNIX_EPOCH};
-use ictl_device::{Device, DeviceError, Tunnel};
+use ictl_device::{Device, DeviceError, SYSFS_USB, Tunnel, UsbDevice};
use ictl_wda::{WdaClient, WdaError, WdaRunner, http::DeviceTransport};
use crate::core::{Daemon, Inner, close_hid};
@@ -17,7 +17,6 @@ const WDA_START_TIMEOUT: Duration = Duration::from_secs(120);
/// HID 会话空闲这么久就关掉。它持有屏幕媒体流,开着时 iOS 当作屏幕被远程查看:不会自动锁屏,
/// 还会弹「viewed remotely」通知。重开约 0.5 秒
pub(crate) const HID_IDLE: Duration = Duration::from_secs(30);
-pub(crate) const SYSFS_USB: &str = "/sys/bus/usb/devices";
/// usbmuxd 起来后这么久内就退出,算「起不来」,按退避重试
const USBMUXD_QUICK_EXIT: Duration = Duration::from_secs(30);
const USBMUXD_MAX_DELAY: Duration = Duration::from_secs(300);
@@ -137,7 +136,7 @@ impl Daemon {
match target {
None => self.offline(g).await,
- Some(d) => self.online(g, &d.udid).await,
+ Some(d) => self.online(g, &d).await,
}
let now = Instant::now();
@@ -176,25 +175,26 @@ impl Daemon {
}
}
- async fn online(&self, g: &mut Inner, udid: &str) {
- if g.device.as_ref().map(|d| d.udid.as_str()) != Some(udid) {
- self.drop_session(g).await;
- match Device::find(Some(udid)).await {
- Ok(d) => {
- g.info = d.info().await.ok();
- let model = g
- .info
- .as_ref()
- .map(|i| format!(" {} iOS {}", i.product_type, i.product_version))
- .unwrap_or_default();
- self.log.log(&format!("手机在线{model}"));
- g.device = Some(d);
- }
- Err(e) => {
- self.log.log(&format!("打开设备失败:{e}"));
- return;
- }
+ async fn online(&self, g: &mut Inner, seen: &UsbDevice) {
+ // 只比 UDID 不够:断开几秒又接上(短于离线判定、落在两轮巡检之间)时 UDID 不变,
+ // usbmuxd 却换了编号,旧句柄的每个连接都报 bad device,永远恢复不了
+ if !g.device.as_ref().is_some_and(|d| d.is_connection(seen)) {
+ if let Some(old) = g.device.take()
+ && old.udid == seen.udid
+ {
+ self.log.log(&format!(
+ "手机重新接入(usbmuxd 编号 {} → {}),重建连接",
+ old.device_id(),
+ seen.device_id
+ ));
}
+ self.drop_session(g).await;
+ let d = Device::from_usb(seen);
+ g.info = d.info().await.ok();
+ let model =
+ g.info.as_ref().map(|i| format!(" {} iOS {}", i.product_type, i.product_version)).unwrap_or_default();
+ self.log.log(&format!("手机在线{model}"));
+ g.device = Some(d);
g.backoff.reset();
if let Some(since) = g.offline_since.take()
&& g.dedup.was_sent("offline")
diff --git a/crates/ictl-device/src/lib.rs b/crates/ictl-device/src/lib.rs
index 67394b3..69f3729 100644
--- a/crates/ictl-device/src/lib.rs
+++ b/crates/ictl-device/src/lib.rs
@@ -134,6 +134,32 @@ pub fn apple_usb_present(root: &Path) -> bool {
.any(|e| std::fs::read_to_string(e.path().join("idVendor")).map(|v| v.trim() == "05ac").unwrap_or(false))
}
+/// Linux 上 USB 设备在 sysfs 里的目录
+pub const SYSFS_USB: &str = "/sys/bus/usb/devices";
+
+/// 宿主机 USB 上有没有 iPhone/iPad:Linux 读 sysfs([`apple_usb_present`]),macOS 查 IORegistry。
+/// 判断不了(其他系统、`ioreg` 运行失败)返回 `None`,调用方应跳过这项检查而不是当成「没有」。
+pub async fn host_apple_usb_present() -> Option<bool> {
+ if cfg!(target_os = "linux") {
+ return Some(apple_usb_present(Path::new(SYSFS_USB)));
+ }
+ if !cfg!(target_os = "macos") {
+ return None;
+ }
+ // Mac 上没有 sysfs;Apple Silicon 自带的 Apple 设备(键盘、触控板)也不在 IOUSB 平面上,但外接的 Apple 配件会在,
+ // 所以按节点名认手机而不是只看厂商号
+ let out = tokio::process::Command::new("/usr/sbin/ioreg").args(["-p", "IOUSB", "-w0"]).output().await.ok()?;
+ out.status.success().then(|| ioreg_has_ios_device(&String::from_utf8_lossy(&out.stdout)))
+}
+
+/// `ioreg -p IOUSB` 的输出里有没有 iPhone/iPad/iPod 节点(形如 `+-o iPhone@00100000 <class IOUSBHostDevice, …>`)
+fn ioreg_has_ios_device(out: &str) -> bool {
+ out.lines().filter_map(|l| l.split("+-o ").nth(1)).any(|node| {
+ let name = node.split('@').next().unwrap_or("");
+ ["iPhone", "iPad", "iPod"].contains(&name)
+ })
+}
+
/// usbmuxd 看到的 USB 设备(不含网络设备)。usbmuxd 没在运行时返回错误。
pub async fn list_devices() -> Result<Vec<UsbDevice>> {
// 不用 UsbmuxdConnection::default():它固定连 /var/run/usbmuxd,不看 USBMUXD_SOCKET_ADDRESS
@@ -163,6 +189,11 @@ impl Device {
None => devices.into_iter().next(),
}
.ok_or(DeviceError::NotConnected)?;
+ Ok(Self::from_usb(&dev))
+ }
+
+ /// 用 [`list_devices`] 列出的一项建句柄(不连 usbmuxd)
+ pub fn from_usb(dev: &UsbDevice) -> Self {
let provider = UsbmuxdProvider {
addr: usbmuxd_addr(),
tag: dev.device_id,
@@ -170,7 +201,17 @@ impl Device {
device_id: dev.device_id,
label: LABEL.into(),
};
- Ok(Self { udid: dev.udid, provider: Arc::new(provider) })
+ Self { udid: dev.udid.clone(), provider: Arc::new(provider) }
+ }
+
+ /// usbmuxd 给这次连接分的编号。拔插、USB 重新枚举后会变(UDID 不变),旧编号的连接全部失效
+ pub fn device_id(&self) -> u32 {
+ self.provider.device_id
+ }
+
+ /// 是不是 `dev` 这一次连接:UDID 和 usbmuxd 编号都要相同
+ pub fn is_connection(&self, dev: &UsbDevice) -> bool {
+ self.udid == dev.udid && self.device_id() == dev.device_id
}
/// 给 XCTest、WDA 等需要自己建连接的组件用
@@ -336,3 +377,32 @@ impl Tunnel {
self.close_hid().await;
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn same_udid_new_mux_id_is_new_connection() {
+ let first = UsbDevice { udid: "00008130-0019295E012B803A".into(), device_id: 2 };
+ let d = Device::from_usb(&first);
+ assert_eq!(d.device_id(), 2);
+ assert!(d.is_connection(&first));
+ // 拔插后 usbmuxd 重新编号:UDID 相同也要当成新连接
+ assert!(!d.is_connection(&UsbDevice { device_id: 3, ..first.clone() }));
+ assert!(!d.is_connection(&UsbDevice { udid: "other".into(), ..first }));
+ }
+
+ #[test]
+ fn ioreg_finds_phone_node() {
+ let with = "+-o Root <class IORegistryEntry, id 0x100000100, retain 35>
+ +-o AppleT8122USBXHCI@00000000 <class AppleT8122USBXHCI, id 0x1000003f8, registered>
+ | +-o iPhone@00100000 <class IOUSBHostDevice, id 0x10009fe32, registered, matched>
+ +-o AppleT8122USBXHCI@02000000 <class AppleT8122USBXHCI, id 0x100000424, registered>";
+ assert!(ioreg_has_ios_device(with));
+ let without = "+-o Root <class IORegistryEntry>
+ +-o AppleT8122USBXHCI@00000000 <class AppleT8122USBXHCI>
+ | +-o Magic Keyboard@00100000 <class IOUSBHostDevice>";
+ assert!(!ioreg_has_ios_device(without));
+ }
+}
diff --git a/docs/dev/macos-verification.md b/docs/dev/macos-verification.md
new file mode 100644
index 0000000..98254cd
--- /dev/null
+++ b/docs/dev/macos-verification.md
@@ -0,0 +1,235 @@
+# macOS 真机验证
+
+CI 已经确认项目在 macOS(Apple Silicon)上能编译、链接,单元测试全部通过(PR #12),但单元测试不连手机。这份文档是在一台插着 iPhone 的 Mac 上要跑的步骤,换了 macOS、iOS 版本或机型时可以照着重跑一遍。
+
+## 已有的验证记录
+
+**2026-11-03,通过。** MacBook Pro(Mac15,6,M3 Pro)/ macOS 26.6.2,没装 Xcode;iPhone 15 Pro Max / iOS 27.0.1;普通用户、`ICTL_MANAGE_USBMUXD=0`、前台运行。
+
+| 项目 | 结果 |
+|---|---|
+| 第 0~1 步 usbmuxd、setup、doctor | ✅(配对沿用了手机和这台 Mac 已有的配对) |
+| 第 2 步 ddi / screenshot / hid / e2e | ✅ e2e 11 项共 8.3 秒 |
+| 第 3 步 回归脚本 | ✅ 14/14 |
+| 第 4 步 A 基线 / B Finder | ✅ 20/20 / 20/20 |
+| 第 4 步 C Xcode | 跳过(没装 Xcode) |
+| 第 4 步 D soak 30 分钟 | ✅ 530/530,没断开 |
+| 第 4 步 E 拔插 / 锁屏 / 重启 | ✅ 都自动恢复 |
+
+和 `remoted` 不会抢连接:所有断开都是 USB 物理层先断,`remoted` 只是跟着断。
+
+验证中发现并修复的问题(PR #14):
+- USB 断开几秒又接上、整段落在两次巡检之间时,守护进程继续用 usbmuxd 的旧设备编号,一直报 `bad device`,不会恢复。Linux 上也会发生。
+- `doctor` 在 macOS 上误报「USB 上没有 Apple 设备」,修复提示是 Linux 的说法。
+- 手机开着「80% 上限」、Mac 用电池时,USB 大约每分钟断开一次(见下面「准备」)。
+
+还没覆盖:Xcode 打开时的共存、`setup` 自己发起配对、开发者镜像的下载和挂载(每次都已由 macOS 挂好)、停掉守护进程后「配对的电脑」图标是否消失、Intel Mac。
+
+## 要回答的问题
+
+| # | 问题 | 通过的标准 |
+|---|---|---|
+| 1 | 系统自带的 usbmuxd 能不能直接用,配对能不能完成 | `setup` 走完 6 步,`status` 显示就绪 |
+| 2 | 隧道、开发者镜像、截图、HID 是否正常 | `debug` 的几项检查都通过 |
+| 3 | WDA 和 MCP 工具是否正常 | 回归脚本默认步骤全部成功 |
+| 4 | 和 macOS 自带的 `remoted` 会不会抢连接 | 开着 Finder 连续操作约 30 分钟不掉线 |
+
+第 4 项风险最大:插上 iPhone 后,macOS 的 `remoted`、`remotepairingd` 会自己和手机建立 CoreDevice 连接。pymobiledevice3 记录过,同一台电脑连手机的 RSD 服务时,后来的连接会把先前的挤掉。本项目经 USB 走 CoreDeviceProxy 建自己的隧道,理论上来源地址不同,但只能实测确认。
+
+## 准备
+
+- **Mac**:Apple Silicon。Intel Mac 也可以测,结果单独记录。
+- **iPhone**:iOS 17.4 以上,项目实测过的是 iPhone 15 Pro Max(iOS 27.0.1)。用**数据线**连接。
+- **Apple ID**:免费的即可,建议用专门的账号,不用主账号。
+- **系统语言**:回归脚本的默认步骤按中文 App 名(「时钟」「设置」)操作,手机最好设为简体中文;不是的话第 3 步要改步骤。
+- **不需要装 Xcode**。如果已经装了,第 4 步多测一个场景。
+- **充电**:把手机「设置 → 电池 → 充电」的上限改成 100%,Mac 最好接上电源。开着「80% 上限」时,手机在 80% 附近反复开始、停止充电,每次 USB-C 重新协商供电都会让 USB 断开 3~5 秒,第 4 步会大面积失败。测完再改回来。
+
+### 安装
+
+```bash
+xcode-select --install # 命令行工具:C 编译器、git(已装会提示)
+curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Rust,1.88 以上即可
+git clone https://github.com/Derrors/iphone-control && cd iphone-control
+cargo install --path apps/iphone-control --locked # 装到 ~/.cargo/bin/iphone-control
+iphone-control --version
+```
+
+### 注意事项
+
+- **全程用普通用户运行,不要 sudo。** 以 root 运行时,守护进程会自己启动一个 usbmuxd,和系统的冲突。保险起见,每个终端先执行:
+ ```bash
+ export ICTL_MANAGE_USBMUXD=0
+ ```
+- 数据目录是 `~/.local/share/iphone-control`,控制接口在 `~/.local/share/iphone-control/ctl.sock`(macOS 没有 `XDG_RUNTIME_DIR`)。
+- 同一时间只能有一个程序控制手机:守护进程、`iphone-control debug …`、Xcode 的 UI 测试不要同时跑。
+
+### 记录环境
+
+```bash
+sw_vers; uname -m; rustc -V; iphone-control --version
+```
+
+再记下 iPhone 型号和 iOS 版本,填到文末的结果表里。
+
+## 第 0 步:系统 usbmuxd 能看到手机
+
+```bash
+ls -l /var/run/usbmuxd # 应该是一个 socket(s 开头)
+```
+
+插上手机。macOS 弹出「允许配件连接」时点「允许」。手机上弹出「要信任此电脑吗?」时**先不要点**,留到第 1 步由 `setup` 处理;如果已经点了,也没关系,在结果里注明。
+
+## 第 1 步:配对、开发者模式、签名
+
+终端 A,前台运行守护进程,日志直接打印在这里:
+
+```bash
+iphone-control daemon
+```
+
+终端 B,运行安装向导:
+
+```bash
+iphone-control setup
+```
+
+逐步观察并记录:
+
+| 步骤 | 期望 | 要特别留意 |
+|---|---|---|
+| [1/6] 等待手机连接 | 打印手机 UDID | 一直等不到:说明经系统 usbmuxd 找不到设备 |
+| [2/6] 配对 | 「已配对」或「配对成功」 | 配对记录由 macOS 的 usbmuxd 保存(`/var/db/lockdown`)。如果报错,记下原文,然后在 Finder 里信任这台电脑,再重跑 `setup`,看能否复用 Finder 的配对 |
+| [3/6] 开发者模式 | 「已打开」,或按提示在手机上打开并重启 | 手机重启后能否自动恢复连接 |
+| [4/6] 登录 Apple ID | 登录成功 | 和平台无关,只要能通过即可 |
+| [5/6] 签名并安装 WDA | 安装成功 | 第一次会下载未签名的 WDA(核对 sha256) |
+| [6/6] 等待 WDA 启动 | 「WDA 就绪」 | 首次要在手机「设置 → 通用 → VPN 与设备管理」里信任你的 Apple ID;弹出「为 XCTest 输入 iPhone 密码」时输入锁屏密码 |
+
+然后:
+
+```bash
+iphone-control status # 状态应为就绪;记下「WDA」那一行的 Bundle ID,第 2 步要用
+iphone-control doctor # 每一项都应是 ✅
+```
+
+没合入 PR #14 的版本,`doctor` 会误报「❌ USB 上没有 Apple 设备」,修复提示也是 Linux 的说法(`systemctl`、udev),可以忽略。
+
+## 第 2 步:隧道、开发者镜像、截图、HID
+
+这些检查直接操作手机,**先在终端 A 按 Ctrl-C 停掉守护进程**。停掉后,手机灵动岛(或状态栏)上「配对的电脑」图标应该在几秒内消失;如果一直不消失,记录下来。
+
+`--width`、`--height` 是屏幕的点尺寸,默认 430×932(Pro Max 机型)。其他机型请换成对应尺寸(例如 6.1 英寸 Pro 是 393×852)。
+
+```bash
+# 开发者镜像:已挂载就报告版本,否则下载并挂载
+iphone-control debug ddi ~/.local/share/iphone-control/ddi
+
+# CoreDevice 截图
+iphone-control debug screenshot /tmp/ictl-shot.png && open /tmp/ictl-shot.png
+
+# HID:先手动打开「设置」;命令会点一下给定坐标(这里是标题区域,没有副作用),再按 Home
+iphone-control debug --width 430 --height 932 hid 215 120
+
+# 端到端:隧道 → 镜像 → WDA → 截图 → 读元素 → 点「设置」→ Home,再用 HID 重做一遍
+iphone-control debug --width 430 --height 932 e2e <第 1 步记下的 WDA Bundle ID> --out /tmp/ictl-e2e.png
+```
+
+HID 检查以手机上的实际效果为准(是否真的回到了主屏幕),命令返回成功不代表生效。
+
+## 第 3 步:通过 MCP 跑回归脚本
+
+重新启动守护进程(终端 A:`iphone-control daemon`),等 `iphone-control status` 显示就绪后,在终端 B 运行:
+
+```bash
+python3 --version # 需要 3.10 以上;命令行工具自带的 python3 可能是 3.9,可用 brew install python 或 uv
+python3 -m venv .venv && .venv/bin/pip install -r tests/device/requirements.txt
+MCP_CMD="iphone-control mcp" .venv/bin/python tests/device/run.py
+```
+
+默认步骤都是无害的操作(Home、时钟 App 的标签页、Spotlight 搜索)。每一步都要成功,截图保存在 `./shots`。
+
+可选:用 `iphone-control mcp-config` 打印注册命令,接入 Claude Code,让它实际操作几分钟。
+
+## 第 4 步:和 remoted 共存
+
+这一步回答最关键的问题。开三个窗口同时观察:
+
+```bash
+# 窗口 1:守护进程(第 3 步已在运行)
+
+# 窗口 2:守护进程的事件日志
+tail -f ~/.local/share/iphone-control/logs/daemon.log
+
+# 窗口 3:macOS 系统服务的日志(要写全路径:zsh 有个同名的内置命令 log)
+/usr/bin/log stream --style compact \
+ --predicate 'process == "remoted" OR process == "remotepairingd"' | tee ~/remoted.log
+```
+
+每个场景用下面的循环连续操作约 10 分钟(每轮约半分钟):
+
+```bash
+export MCP_CMD="iphone-control mcp"
+for i in $(seq 1 20); do
+ .venv/bin/python tests/device/run.py > /tmp/ictl-round-$i.log 2>&1 && echo "第 $i 轮 ok" || echo "第 $i 轮失败"
+ sleep 5
+done
+```
+
+| 场景 | 做法 |
+|---|---|
+| A. 基线 | 关掉 Finder 窗口,只跑循环 |
+| B. Finder | 打开 Finder,在侧边栏选中这部 iPhone,停在它的页面上,跑循环;中途切换几次「通用」「文件」等标签 |
+| C. Xcode(装了才测) | 打开 Xcode 的 Window → Devices and Simulators 并选中这部手机,跑循环 |
+| D. 隧道长测 | 停掉守护进程,Finder 保持选中手机,运行 `iphone-control debug soak --minutes 30`(同一条隧道持续截图) |
+| E. 恢复 | 守护进程运行中:拔线再插回;锁屏再解锁;重启手机(重启后要手动解锁并输一次密码)。每次都看多久回到就绪 |
+
+每个场景看三处:
+
+- 循环里有没有失败的轮次(失败时看 `/tmp/ictl-round-N.log`)。
+- `daemon.log` 里有没有反复出现隧道重建、WDA 重启、离线这类记录。
+- `remoted.log` 里有没有 `interrupted`、`disconnect` 之类的记录,时间点是否和我们的操作、失败对得上。
+
+判定:
+
+- **通过**:A、B(以及 C)全部轮次成功,D 跑满 30 分钟不断开,E 都能自动恢复。
+- **部分通过**:偶尔断开但能自动恢复。记下频率和触发条件,再决定要不要处理。
+- **不通过**:只要开着 Finder 或 Xcode 就持续断开。需要另想办法(例如复用 macOS 自己的隧道),先不宣布支持。
+
+## 已知差异(不算失败)
+
+- 数据目录在 `~/.local/share` 下,不是 Mac 习惯的 `~/Library/Application Support`。
+- 还没有 launchd 配置,只能前台运行。
+- 不能用 Docker:Docker Desktop 在 Mac 上不支持 USB 直通。
+
+## 清理
+
+```bash
+# 在终端 A 按 Ctrl-C 停掉守护进程
+rm -rf ~/.local/share/iphone-control # 删数据目录(含 Apple ID 会话和签好的 WDA)
+cargo uninstall iphone-control
+```
+
+手机上:删除 WebDriverAgent 这个 App;「设置 → 通用 → VPN 与设备管理」里的描述文件随 App 一起消失。
+
+## 结果
+
+把下面这张表填好,连同失败时的日志原文,贴到 issue 或 PR 里。
+
+| 项目 | 结果 |
+|---|---|
+| Mac 型号 / macOS 版本 | |
+| iPhone 型号 / iOS 版本 | |
+| 是否装了 Xcode | |
+| 第 0 步 usbmuxd 看到手机 | |
+| 第 1 步 配对方式(setup / Finder)| |
+| 第 1 步 setup 6 步 | |
+| 第 1 步 doctor | |
+| 第 2 步 ddi / screenshot / hid / e2e | |
+| 第 2 步 停掉后「配对的电脑」图标消失 | |
+| 第 3 步 回归脚本 | |
+| 第 4 步 A 基线 | |
+| 第 4 步 B Finder | |
+| 第 4 步 C Xcode | |
+| 第 4 步 D soak 30 分钟 | |
+| 第 4 步 E 拔插 / 锁屏 / 重启恢复 | |
+| 其他现象 | |
diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md
index 5c04afd..781c3b1 100644
--- a/docs/troubleshooting.md
+++ b/docs/troubleshooting.md
@@ -31,6 +31,7 @@ The program's own messages are in Simplified Chinese; the Chinese text is quoted
- **Two usbmuxd instances:** a host `usbmuxd` (installed by many distributions, started by udev on plug-in) takes the phone away from the container. Mask it with `sudo systemctl mask usbmuxd`, or, for a source install, use the system one and don't run the container.
- **Another tool holds the phone:** Xcode-less tools such as go-ios or pymobiledevice3 running at the same time can conflict. Stop them.
- **Cable:** some cables only charge. If `lsusb` doesn't show an Apple device (vendor `05ac`), try another cable or port.
+- **Drops every minute or so while charging:** with *Settings → Battery → Charging → 80% Limit* on, the phone keeps starting and stopping charging near 80%, and each switch renegotiates USB-C power, which briefly disconnects USB (3–5 s). The daemon reconnects by itself, but in-flight actions fail. Set the limit to 100% while the phone is used for automation.
## WebDriverAgent won't start
@@ -56,10 +57,17 @@ The program's own messages are in Simplified Chinese; the Chinese text is quoted
The HID fallback keeps a screen-mirroring session open while it is in use (the Dynamic Island shows a computer icon) and closes it after 30 seconds of inactivity. If the icon stays, restart the daemon; stopping it closes the session.
+## macOS
+
+- **No Docker:** Docker Desktop has no USB passthrough; run the binary directly as your regular user ([macOS guide](https://derrors.github.io/iphone-control/en/deploy/macos)). Don't run it with `sudo`: as root it starts a second usbmuxd and uses Linux system paths.
+- **usbmuxd:** it is part of macOS and always running. If `doctor` can't reach it: `sudo launchctl kickstart -k system/com.apple.usbmuxd`.
+- **Finder** can stay open on the phone; macOS's `remoted` doesn't take the connection away. Xcode's *Devices and Simulators* window is untested.
+
## Logs
- Container: `docker logs iphone-control`, and the event log at `/var/lib/iphone-control/logs/daemon.log` inside the container (`./data/logs/` on the host).
- Source install: `journalctl --user -u iphone-control` and `~/.local/share/iphone-control/logs/`.
+- macOS: the terminal running `iphone-control daemon`, and `~/.local/share/iphone-control/logs/`. For system logs use `/usr/bin/log` (zsh has a built-in `log`).
- More detail: set `ICTL_LOG=info,ictl_wda::http=debug` to log every WebDriverAgent request with its duration. Remove it afterwards; it is verbose.
## Reporting a bug
diff --git a/website/.vitepress/config.mts b/website/.vitepress/config.mts
index 38248b8..8c21912 100644
--- a/website/.vitepress/config.mts
+++ b/website/.vitepress/config.mts
@@ -7,7 +7,7 @@ export default defineConfig({
// 发布到 GitHub Pages:https://derrors.github.io/iphone-control/
base: '/iphone-control/',
title: 'iphone-control',
- description: '在 Linux 上通过 USB 控制真实 iPhone,以 MCP 工具交给 AI agent',
+ description: '在 Linux 或 macOS 上通过 USB 控制真实 iPhone,以 MCP 工具交给 AI agent',
head: [['link', { rel: 'icon', type: 'image/svg+xml', href: '/iphone-control/logo.svg' }]],
lastUpdated: true,
cleanUrls: true,
@@ -46,6 +46,7 @@ export default defineConfig({
items: [
{ text: 'Docker', link: '/deploy/docker' },
{ text: '从源码 / 二进制', link: '/deploy/source' },
+ { text: 'macOS', link: '/deploy/macos' },
{ text: '数据与备份', link: '/deploy/backup' },
],
},
@@ -77,7 +78,7 @@ export default defineConfig({
en: {
label: 'English',
lang: 'en-US',
- description: 'Control a real iPhone over USB from Linux and hand it to AI agents as MCP tools',
+ description: 'Control a real iPhone over USB from Linux or macOS and hand it to AI agents as MCP tools',
themeConfig: {
nav: [
{ text: 'Home', link: '/en/' },
@@ -108,6 +109,7 @@ export default defineConfig({
items: [
{ text: 'Docker', link: '/en/deploy/docker' },
{ text: 'Source / Binary', link: '/en/deploy/source' },
+ { text: 'macOS', link: '/en/deploy/macos' },
{ text: 'Data and Backups', link: '/en/deploy/backup' },
],
},
diff --git a/website/deploy/backup.md b/website/deploy/backup.md
index 73c58ab..489ae12 100644
--- a/website/deploy/backup.md
+++ b/website/deploy/backup.md
@@ -12,7 +12,7 @@
| `state.json` | 状态快照、上次重签结果 | 自动重建 |
| `logs/` | 日志 | — |
-位置:Docker 部署是仓库目录下的 `./data`(root 所有,权限 0700);从源码运行是 `~/.local/share/iphone-control`,配对记录在系统的 `/var/lib/lockdown`。
+位置:Docker 部署是仓库目录下的 `./data`(root 所有,权限 0700);从源码运行是 `~/.local/share/iphone-control`,配对记录在系统的 `/var/lib/lockdown`;macOS 上数据目录也是 `~/.local/share/iphone-control`,配对记录由系统保存在 `/var/db/lockdown`(和 Finder 共用)。
::: danger 这些是秘密
数据目录能用来登录你的 Apple ID 开发者账号、免确认地连接手机,开启自动解锁时还有明文锁屏密码。不要提交到 git,不要发给别人,备份也要加密保存。
@@ -35,6 +35,8 @@ sudo tar czf lockdown.tar.gz /var/lib/lockdown # 配对记录
systemctl --user start iphone-control
```
+macOS:先在守护进程的终端按 Ctrl-C 停掉,再执行上面的第二条 `tar`。配对记录归系统管理,不用备份,换了 Mac 在手机上重新点一次「信任」即可。
+
## 迁移到新主机
把数据目录(从源码运行时还有 `/var/lib/lockdown`)原样恢复到新主机的同一位置,再启动即可,不需要重新配对、登录。
diff --git a/website/deploy/macos.md b/website/deploy/macos.md
new file mode 100644
index 0000000..dca4d73
--- /dev/null
+++ b/website/deploy/macos.md
@@ -0,0 +1,135 @@
+# macOS
+
+iphone-control 也能直接跑在 Mac 上:用 macOS 自带的 usbmuxd,不需要 Xcode,也不需要付费开发者账号。和 Linux 上从源码运行基本一样,区别见文末的[已知差异](#已知差异)。
+
+::: info 验证情况
+已在 MacBook Pro(Apple M3 Pro)/ macOS 26.6.2 + iPhone 15 Pro Max / iOS 27.0.1 上完整验证:安装向导、全部 MCP 工具、开着 Finder 连续操作、同一条隧道连续 30 分钟、拔插和手机重启后自动恢复。Intel Mac 还没测过。验证步骤和结果见 [macOS 真机验证](https://github.com/Derrors/iphone-control/blob/main/docs/dev/macos-verification.md)。
+:::
+
+## 需要
+
+- Apple Silicon 的 Mac
+- Xcode 命令行工具(提供 C 编译器和 git),**不需要**完整的 Xcode
+- Rust 1.88 以上
+- 一部 iOS 17 以上的 iPhone,用能**传数据**的线连接
+- 一个免费 Apple ID(建议专门注册一个)
+
+::: warning 不能用 Docker
+Docker Desktop 在 Mac 上把容器跑在 Linux 虚拟机里,不支持 USB 直通,容器看不到手机。在 Mac 上只能直接运行程序。
+:::
+
+## 安装
+
+目前 Releases 里没有 macOS 的预编译二进制,要从源码编译(M3 Pro 上约 2 分半):
+
+```bash
+xcode-select --install # 已经装过会提示
+curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # 装好后按提示重开终端
+git clone https://github.com/Derrors/iphone-control && cd iphone-control
+cargo install --path apps/iphone-control --locked # 装到 ~/.cargo/bin/iphone-control
+iphone-control --version
+```
+
+## 运行
+
+**全程用普通用户运行,不要加 sudo。** macOS 自带的 usbmuxd 一直在运行,守护进程直接用它;以 root 运行时守护进程会自己再启动一个 usbmuxd 和系统的抢设备,数据目录和控制接口也会换成按 Linux 设的系统路径(`/var/lib`、`/run`)。
+
+在一个终端里运行守护进程,日志直接打印在这里:
+
+```bash
+iphone-control daemon
+```
+
+另开一个终端运行安装向导:
+
+```bash
+iphone-control setup
+```
+
+向导的六步和 Linux 上一样,手机上要做的事见[快速开始](../guide/getting-started#_2-运行安装向导)。如果这部手机已经在 Finder 里信任过这台 Mac,配对这一步会直接显示「已配对」。
+
+向导显示「WDA 就绪」后,接入 AI 客户端:
+
+```bash
+iphone-control mcp-config # 打印注册命令,复制运行即可
+```
+
+它打印的命令形如 `claude mcp add iphone -s user -- /Users/you/.cargo/bin/iphone-control --socket /Users/you/.local/share/iphone-control/ctl.sock mcp`。其他客户端见[接入 AI 客户端](../guide/mcp-clients)。
+
+### 配置
+
+配置写在 `~/.config/iphone-control/env`(格式同仓库里的 `.env.example`),启动守护进程前先加载:
+
+```bash
+mkdir -p ~/.config/iphone-control
+cp .env.example ~/.config/iphone-control/env # 按需填代理、通知
+set -a; . ~/.config/iphone-control/env; set +a
+iphone-control daemon
+```
+
+改了配置要重启守护进程(Ctrl-C 后重新运行)。变量说明见[配置](../guide/configuration)。
+
+### 保持运行
+
+还没有 launchd 配置,守护进程要留在一个终端(或 tmux)里。Mac 睡眠时它也会暂停,长时间无人值守时用 `caffeinate` 防止睡眠:
+
+```bash
+caffeinate -i iphone-control daemon
+```
+
+## 让 USB 连接稳定
+
+- **把手机的充电上限改成 100%**:设置 → 电池 → 充电。开着「80% 上限」时,手机在 80% 附近反复开始、停止充电,每次 USB-C 都会重新协商供电,USB 断开 3~5 秒,大约每分钟一次。守护进程能自己重连,但正在执行的操作会失败。
+- 长时间运行时 Mac 最好接上电源。
+- Finder 可以一直开着、停在手机页面,不会抢连接。
+
+## 日常命令
+
+和 Linux 一样,直接运行,不用加 `docker exec`:
+
+```bash
+iphone-control status # 状态、描述文件还剩多久、最近日志
+iphone-control doctor # 逐层诊断
+```
+
+看 macOS 系统服务的日志时要写全路径 `/usr/bin/log`:zsh 有一个同名的内置命令 `log`,直接写 `log stream` 会报 `too many arguments`。
+
+usbmuxd 本身出问题(`doctor` 报连不上 usbmuxd)时重启它:
+
+```bash
+sudo launchctl kickstart -k system/com.apple.usbmuxd
+```
+
+## 升级
+
+```bash
+cd iphone-control && git pull
+cargo install --path apps/iphone-control --locked
+```
+
+然后重启守护进程。
+
+## 卸载
+
+先在守护进程的终端按 Ctrl-C 停掉,然后:
+
+```bash
+cargo uninstall iphone-control
+rm -rf ~/.local/share/iphone-control ~/.config/iphone-control # 会删掉 Apple ID 会话和签好的 WDA
+```
+
+手机上删除 WebDriverAgent 这个 App,「VPN 与设备管理」里的描述文件会随它一起消失。
+
+## 已知差异
+
+| | Linux(从源码运行) | macOS |
+|---|---|---|
+| 安装 | 预编译二进制或从源码编译 | 只能从源码编译 |
+| 常驻 | systemd 用户服务 | 还没有 launchd 配置,在终端里前台运行 |
+| usbmuxd | 系统包,插上手机时由 udev 拉起 | macOS 自带,一直在运行 |
+| 数据目录 | `~/.local/share/iphone-control` | 同左(不是 Mac 习惯的 `~/Library/Application Support`) |
+| 控制接口 | `$XDG_RUNTIME_DIR/iphone-control/ctl.sock` | `~/.local/share/iphone-control/ctl.sock` |
+| 配对记录 | `/var/lib/lockdown` | `/var/db/lockdown`(和 Finder 共用) |
+| Docker | 支持 | 不支持 |
+
+还没在 Mac 上验证过的:Xcode 的「设备与模拟器」窗口开着时会不会抢连接、手机第一次在这台 Mac 上配对的流程、Intel Mac。遇到问题欢迎[反馈](https://github.com/Derrors/iphone-control/issues)。
diff --git a/website/deploy/source.md b/website/deploy/source.md
index 3f7ed4f..19010d8 100644
--- a/website/deploy/source.md
+++ b/website/deploy/source.md
@@ -1,6 +1,6 @@
# 从源码 / 二进制运行
-不用 Docker,以普通用户直接运行。需要系统的 usbmuxd(它由 udev 在插上手机时拉起)。
+在 Linux 上不用 Docker,以普通用户直接运行。需要系统的 usbmuxd(它由 udev 在插上手机时拉起)。在 Mac 上见 [macOS](./macos)。
## 安装
diff --git a/website/en/deploy/backup.md b/website/en/deploy/backup.md
index f438894..9f62603 100644
--- a/website/en/deploy/backup.md
+++ b/website/en/deploy/backup.md
@@ -12,7 +12,7 @@
| `state.json` | State snapshot, last signing result | Rebuilt automatically |
| `logs/` | Logs | — |
-Location: `./data` in the repository directory for Docker (owned by root, mode 0700); `~/.local/share/iphone-control` for a source install, with pairing records in the system's `/var/lib/lockdown`.
+Location: `./data` in the repository directory for Docker (owned by root, mode 0700); `~/.local/share/iphone-control` for a source install, with pairing records in the system's `/var/lib/lockdown`. On macOS the data directory is also `~/.local/share/iphone-control`, and the system keeps pairing records in `/var/db/lockdown` (shared with Finder).
::: danger These are secrets
The data directory can log in to your Apple ID developer account, connect to the phone without confirmation, and — with auto-unlock — contains the passcode in plain text. Never commit or share it, and keep backups encrypted.
@@ -35,6 +35,8 @@ sudo tar czf lockdown.tar.gz /var/lib/lockdown # pairing records
systemctl --user start iphone-control
```
+macOS: stop the daemon with Ctrl-C in its terminal, then run the second `tar` above. Pairing records belong to the system and don't need a backup; on a new Mac, tap *Trust* on the phone once more.
+
## Move to a new host
Restore the data directory (and `/var/lib/lockdown` for a source install) to the same location on the new host and start it; no new pairing or login is needed.
diff --git a/website/en/deploy/macos.md b/website/en/deploy/macos.md
new file mode 100644
index 0000000..fcaa252
--- /dev/null
+++ b/website/en/deploy/macos.md
@@ -0,0 +1,135 @@
+# macOS
+
+iphone-control also runs directly on a Mac, using the usbmuxd that ships with macOS. No Xcode and no paid developer account. It works like a source install on Linux; the differences are listed under [Known differences](#known-differences).
+
+::: info Verified
+Fully verified on a MacBook Pro (Apple M3 Pro) / macOS 26.6.2 with an iPhone 15 Pro Max / iOS 27.0.1: the setup wizard, every MCP tool, continuous use with Finder open, one tunnel kept busy for 30 minutes, and recovery after unplugging and phone reboots. Intel Macs are untested. Steps and results: [macOS verification](https://github.com/Derrors/iphone-control/blob/main/docs/dev/macos-verification.md) (in Chinese).
+:::
+
+## You need
+
+- An Apple Silicon Mac
+- The Xcode Command Line Tools (C compiler and git). Full Xcode is **not** needed
+- Rust 1.88 or later
+- An iPhone on iOS 17+, connected with a cable that carries **data**
+- A free Apple ID (a dedicated one is recommended)
+
+::: warning No Docker
+Docker Desktop on a Mac runs containers in a Linux VM without USB passthrough, so a container can't see the phone. Run the program directly.
+:::
+
+## Install
+
+There is no prebuilt macOS binary in Releases yet; build from source (about 2½ minutes on an M3 Pro):
+
+```bash
+xcode-select --install # says so if already installed
+curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # then open a new terminal
+git clone https://github.com/Derrors/iphone-control && cd iphone-control
+cargo install --path apps/iphone-control --locked # installs ~/.cargo/bin/iphone-control
+iphone-control --version
+```
+
+## Run
+
+**Run everything as your regular user, never with sudo.** macOS's own usbmuxd is always running and the daemon uses it. As root, the daemon would start a second usbmuxd that fights the system one, and would switch to Linux system paths (`/var/lib`, `/run`) for its data and control socket.
+
+In one terminal, start the daemon; its log prints there:
+
+```bash
+iphone-control daemon
+```
+
+In a second terminal, run the setup wizard:
+
+```bash
+iphone-control setup
+```
+
+The six steps are the same as on Linux; what to do on the phone is in [Getting Started](../guide/getting-started#_2-run-the-setup-wizard). If the phone already trusts this Mac (from Finder), the pairing step just says it is paired.
+
+When the wizard says WDA is ready (WDA 就绪), connect your AI client:
+
+```bash
+iphone-control mcp-config # prints the registration command; run it
+```
+
+It prints something like `claude mcp add iphone -s user -- /Users/you/.cargo/bin/iphone-control --socket /Users/you/.local/share/iphone-control/ctl.sock mcp`. Other clients: [Connect an AI Client](../guide/mcp-clients).
+
+### Configuration
+
+Settings go in `~/.config/iphone-control/env` (same format as `.env.example` in the repository). Load it before starting the daemon:
+
+```bash
+mkdir -p ~/.config/iphone-control
+cp .env.example ~/.config/iphone-control/env # proxy, notifications, …
+set -a; . ~/.config/iphone-control/env; set +a
+iphone-control daemon
+```
+
+Restart the daemon (Ctrl-C, then run it again) after changing settings. The variables are listed in [Configuration](../guide/configuration).
+
+### Keep it running
+
+There is no launchd configuration yet, so keep the daemon in a terminal (or tmux). It pauses while the Mac sleeps; for long unattended runs, keep the Mac awake with `caffeinate`:
+
+```bash
+caffeinate -i iphone-control daemon
+```
+
+## Keep the USB connection stable
+
+- **Set the phone's charging limit to 100%** under *Settings → Battery → Charging*. With the 80% limit on, the phone keeps starting and stopping charging near 80%, and each switch renegotiates USB-C power, which drops USB for 3–5 seconds about once a minute. The daemon reconnects by itself, but actions in progress fail.
+- For long runs, keep the Mac on power.
+- Finder can stay open on the phone's page; it doesn't take the connection away.
+
+## Everyday commands
+
+Same as on Linux, run directly without `docker exec`:
+
+```bash
+iphone-control status # state, signing time left, recent log
+iphone-control doctor # layer-by-layer checks
+```
+
+To read macOS system logs, use the full path `/usr/bin/log`: zsh has a built-in `log` command, so a bare `log stream` fails with `too many arguments`.
+
+If usbmuxd itself misbehaves (`doctor` can't reach it), restart it:
+
+```bash
+sudo launchctl kickstart -k system/com.apple.usbmuxd
+```
+
+## Upgrade
+
+```bash
+cd iphone-control && git pull
+cargo install --path apps/iphone-control --locked
+```
+
+Then restart the daemon.
+
+## Uninstall
+
+Stop the daemon with Ctrl-C in its terminal, then:
+
+```bash
+cargo uninstall iphone-control
+rm -rf ~/.local/share/iphone-control ~/.config/iphone-control # deletes the Apple ID session and signed WDA
+```
+
+On the phone, delete the WebDriverAgent app; its profile under *VPN & Device Management* goes with it.
+
+## Known differences
+
+| | Linux (source install) | macOS |
+|---|---|---|
+| Install | Prebuilt binary or build from source | Build from source only |
+| Keep running | systemd user service | No launchd configuration yet; run in a terminal |
+| usbmuxd | System package, started by udev on plug-in | Built into macOS, always running |
+| Data directory | `~/.local/share/iphone-control` | Same (not the usual `~/Library/Application Support`) |
+| Control socket | `$XDG_RUNTIME_DIR/iphone-control/ctl.sock` | `~/.local/share/iphone-control/ctl.sock` |
+| Pairing records | `/var/lib/lockdown` | `/var/db/lockdown` (shared with Finder) |
+| Docker | Supported | Not supported |
+
+Not yet verified on a Mac: whether Xcode's *Devices and Simulators* window competes for the connection, pairing a phone with the Mac for the first time, and Intel Macs. [Reports](https://github.com/Derrors/iphone-control/issues) are welcome.
diff --git a/website/en/deploy/source.md b/website/en/deploy/source.md
index f6e3dd3..b271ec7 100644
--- a/website/en/deploy/source.md
+++ b/website/en/deploy/source.md
@@ -1,6 +1,6 @@
# Source / Binary
-Run it directly as a regular user, without Docker. You need the system usbmuxd (udev starts it when the phone is plugged in).
+Run it directly as a regular user on Linux, without Docker. You need the system usbmuxd (udev starts it when the phone is plugged in). On a Mac, see [macOS](./macos).
## Install
diff --git a/website/en/guide/auto-unlock.md b/website/en/guide/auto-unlock.md
index c1a3f8d..27a5a5e 100644
--- a/website/en/guide/auto-unlock.md
+++ b/website/en/guide/auto-unlock.md
@@ -23,6 +23,7 @@ docker exec -it iphone-control iphone-control passcode clear
- After every digit it checks how many digits the passcode field shows and stops at once if they don't match (an incomplete entry is not a wrong attempt); only a first digit that didn't register is retried, up to 3 rounds.
- If the phone is still locked after the full passcode, auto-unlock is **disabled immediately** and you are notified. It never tries a second time, so it can't pile up wrong attempts and trigger data erasure.
- The first unlock after a reboot (BFU) always needs a person.
+- A phone charging on its side goes into **StandBy**, which doesn't bring up the passcode keypad, so auto-unlock fails. Turn it off under *Settings → StandBy* when you use auto-unlock.
## Re-enable after it was disabled
diff --git a/website/en/guide/configuration.md b/website/en/guide/configuration.md
index 91ea51a..189d95c 100644
--- a/website/en/guide/configuration.md
+++ b/website/en/guide/configuration.md
@@ -5,6 +5,7 @@ Everything is configured with environment variables, and all of them are optiona
- **Docker:** in `.env` in the repository directory (copied from `.env.example`); apply with `docker compose up -d`.
- **Just a compose file:** under `environment:` in your `compose.yaml` (or a `.env` next to it plus `env_file`); apply with `docker compose up -d` as well.
- **Source install:** in `~/.config/iphone-control/env` (read by the systemd user service); apply with `systemctl --user restart iphone-control`.
+- **macOS:** also in `~/.config/iphone-control/env`, loaded before starting the daemon; restart the daemon to apply. See [macOS](../deploy/macos#configuration).
## Common
diff --git a/website/en/guide/getting-started.md b/website/en/guide/getting-started.md
index 6f62e7b..91c261b 100644
--- a/website/en/guide/getting-started.md
+++ b/website/en/guide/getting-started.md
@@ -1,6 +1,6 @@
# Getting Started
-Deploying with Docker takes about 15 minutes. Without Docker, see [Source / Binary](../deploy/source).
+Deploying with Docker on Linux takes about 15 minutes. Without Docker, see [Source / Binary](../deploy/source); on a Mac, see [macOS](../deploy/macos) — the setup wizard and client steps are the same as here.
## You need
@@ -10,7 +10,7 @@ Deploying with Docker takes about 15 minutes. Without Docker, see [Source / Bina
- Internet access to Apple and GitHub from the host (set a proxy if needed)
::: warning One phone, one owner
-Don't run two copies of iphone-control, or other usbmuxd-based tools (go-ios, pymobiledevice3, …), against the same phone. If the host has usbmuxd installed, run `sudo systemctl mask usbmuxd` first.
+Don't run two copies of iphone-control, or other usbmuxd-based tools (go-ios, pymobiledevice3, …), against the same phone. If a Linux host has usbmuxd installed, run `sudo systemctl mask usbmuxd` first.
:::
## 1. Start
diff --git a/website/en/guide/mcp-clients.md b/website/en/guide/mcp-clients.md
index a1b3921..6550850 100644
--- a/website/en/guide/mcp-clients.md
+++ b/website/en/guide/mcp-clients.md
@@ -38,6 +38,8 @@ For a source install, use the command that `mcp-config` prints, for example:
}
```
+macOS has no `XDG_RUNTIME_DIR`, so the socket is `~/.local/share/iphone-control/ctl.sock`; again, use what `mcp-config` prints. Claude Desktop's configuration file is `~/Library/Application Support/Claude/claude_desktop_config.json`.
+
::: warning Client and daemon on the same machine
The MCP server reaches the daemon through a local Unix socket. If the client runs on another computer, start it over SSH, e.g. `"command": "ssh", "args": ["host", "docker", "exec", "-i", "iphone-control", "iphone-control", "mcp"]`.
:::
diff --git a/website/en/guide/security.md b/website/en/guide/security.md
index 99fa57e..e788d0c 100644
--- a/website/en/guide/security.md
+++ b/website/en/guide/security.md
@@ -10,7 +10,7 @@ iphone-control is a remote control for a phone: whoever can reach it can do anyt
| Apple ID session, signing key | `account/` in the data directory | Whoever can read the data directory. The Apple ID password is never stored |
| Pairing records | `lockdown/` in the data directory (Docker) | Whoever can read it; it lets the holder talk to the phone over USB without another *Trust* prompt |
| Passcode (only with auto-unlock) | `secrets/passcode`, **plain text** | Whoever can read the data directory |
-| Notification keys | `.env` or the systemd environment file | Whoever can read that file |
+| Notification keys | `.env` or `~/.config/iphone-control/env` | Whoever can read that file |
## Built-in protections
diff --git a/website/en/guide/what-is-iphone-control.md b/website/en/guide/what-is-iphone-control.md
index f23a9b4..e86856f 100644
--- a/website/en/guide/what-is-iphone-control.md
+++ b/website/en/guide/what-is-iphone-control.md
@@ -1,13 +1,13 @@
# What is iphone-control?
-iphone-control lets an AI agent such as Claude use a real iPhone that is plugged into a Linux machine: look at the screen, tap buttons, type, open apps — like a person holding the phone.
+iphone-control lets an AI agent such as Claude use a real iPhone that is plugged into a Linux machine or a Mac: look at the screen, tap buttons, type, open apps — like a person holding the phone.
It works as a set of [MCP](https://modelcontextprotocol.io) (Model Context Protocol) tools, so any MCP client — Claude Code, Claude Desktop, Cursor and others — can use it directly.
## What you can do with it
- Let an agent get things done on the phone: look things up, fill in forms, change settings, play games.
-- Test your own app or website on a real device without a Mac.
+- Test your own app or website on a real device; a Linux box will do, no Mac needed.
- Turn a spare iPhone into a device you can script remotely.
## How it works
@@ -18,15 +18,15 @@ It works as a set of [MCP](https://modelcontextprotocol.io) (Model Context Proto
- A **daemon** runs all the time and owns the phone: it pairs, mounts the Developer Disk Image, opens a tunnel, and runs [WebDriverAgent](https://github.com/appium/WebDriverAgent) (WDA, an agent on top of Apple's XCTest automation) on the phone to read the screen, tap and type.
- The **MCP server** is started by the AI client on demand and simply forwards tool calls to the daemon.
- WDA is signed with your **free Apple ID**. Free signatures expire after 7 days; the daemon re-signs before that.
-- While WDA is unavailable (for example while it restarts), taps, swipes, buttons and screenshots go through CoreDevice HID instead.
+- While WDA is unavailable (for example while it restarts), taps, swipes, buttons and screenshots go through CoreDevice HID instead (iOS 27 and later).
## Compatibility
| | |
|---|---|
-| Host | Linux, x86_64 or arm64; Docker (Compose v2), or Rust 1.88+ to build from source |
-| Phone | iOS 17 or later |
-| Verified on | iPhone 15 Pro Max, iOS 27.0.1 |
+| Host | Linux, x86_64 or arm64: Docker (Compose v2), or Rust 1.88+ to build from source<br>macOS, Apple Silicon: Rust 1.88+ to build from source, see [macOS](../deploy/macos) |
+| Phone | iOS 17 or later; the HID fallback needs iOS 27 or later |
+| Verified on | iPhone 15 Pro Max, iOS 27.0.1 (Linux, macOS)<br>iPhone 12 mini, iOS 26.4.1 (Linux) |
| Account | A free Apple ID; a dedicated one is recommended |
Other models and iOS versions should work but are untested — [reports](https://github.com/Derrors/iphone-control/issues) are welcome.
diff --git a/website/en/index.md b/website/en/index.md
index cb1354f..162acb6 100644
--- a/website/en/index.md
+++ b/website/en/index.md
@@ -4,7 +4,7 @@ layout: home
hero:
name: iphone-control
text: Let AI agents use a real iPhone
- tagline: Control an iPhone over USB from Linux and hand it to Claude and other AI as MCP tools. No Mac, no paid developer account.
+ tagline: Control an iPhone over USB from Linux or a Mac and hand it to Claude and other AI as MCP tools. No Xcode, no paid developer account.
image:
src: /logo.svg
alt: iphone-control
@@ -23,15 +23,15 @@ features:
- icon: 🤖
title: Tools for agents
details: Screenshots, on-screen elements, tap by text, swipe, typing (Chinese too), apps, waiting for pages, multi-step batches — 15 MCP tools
- - icon: 🐧
- title: Just a Linux box
- details: No Mac or Xcode. WebDriverAgent is signed with a free Apple ID and re-signed before the 7-day profile expires
+ - icon: 💻
+ title: Linux or Mac
+ details: No Mac needed on Linux, no Xcode needed on a Mac. WebDriverAgent is signed with a free Apple ID and re-signed before the 7-day profile expires
- icon: 🔁
title: Keeps itself running
details: Pairs, mounts the Developer Disk Image, starts WDA, and recovers after unplugging, reboots and crashes
- icon: 🛟
title: Fallback path
- details: When WDA is down, taps, swipes, buttons and screenshots still work through CoreDevice HID
+ details: When WDA is down, taps, swipes, buttons and screenshots still work through CoreDevice HID (iOS 27+)
- icon: 🔔
title: Tells you when it needs you
details: Bark or Telegram notifications for failed re-signing, expired sessions, reboots that need the passcode, or going offline
@@ -40,7 +40,7 @@ features:
details: WDA is reached through usbmuxd; nothing listens on the network. Auto-unlock is off by default
- icon: 📦
title: One binary
- details: Written in Rust. One Docker command to deploy, or run it from source or a prebuilt binary
+ details: Written in Rust. One Docker command to deploy on Linux, or run it from source or a prebuilt binary; build from source on a Mac
- icon: 🧭
title: Fewer round trips
details: Actions can return the resulting screen after waiting for it to settle, and flag loading pages and blocking alerts
diff --git a/website/en/troubleshoot/faq.md b/website/en/troubleshoot/faq.md
index ea45394..19dd5b3 100644
--- a/website/en/troubleshoot/faq.md
+++ b/website/en/troubleshoot/faq.md
@@ -13,7 +13,7 @@ The program's messages are in Chinese; here is what they mean.
| `status` shows | Meaning | What to do |
|---|---|---|
-| 手机未连接 | usbmuxd sees no phone | Check the cable and unlock the phone; with a host usbmuxd, `sudo systemctl mask usbmuxd` |
+| 手机未连接 | usbmuxd sees no phone | Check the cable and unlock the phone; with a usbmuxd on a Linux host, `sudo systemctl mask usbmuxd` |
| 未配对 | Not paired | Run `setup` and tap *Trust* on the phone |
| 开发者模式未打开 | Developer Mode is off | Run `setup` and follow the prompts |
| 手机锁屏,隧道建不起来 | Not unlocked since the last reboot | Unlock it once by hand |
@@ -29,6 +29,8 @@ The program's messages are in Chinese; here is what they mean.
- **Another tool holds the phone:** go-ios, pymobiledevice3 and similar tools conflict.
- **Cable:** some cables only charge. If `lsusb` shows no Apple device (`05ac`), try another cable or port.
- **After re-plugging:** Docker recovers within about a minute.
+- **Drops about once a minute while charging:** with *Settings → Battery → Charging → 80% Limit* on, the phone keeps starting and stopping charging near 80%, and each switch renegotiates USB-C power, which drops USB for 3–5 seconds. Set the limit to 100% on a phone used for automation.
+- **On a Mac:** Docker can't be used (no USB passthrough); see [macOS](../deploy/macos). usbmuxd is part of macOS; if `doctor` can't reach it, run `sudo launchctl kickstart -k system/com.apple.usbmuxd`.
## WDA won't start
diff --git a/website/guide/auto-unlock.md b/website/guide/auto-unlock.md
index 23e4138..82ccfd5 100644
--- a/website/guide/auto-unlock.md
+++ b/website/guide/auto-unlock.md
@@ -23,6 +23,7 @@ docker exec -it iphone-control iphone-control passcode clear
- 每按一位都核对密码栏的位数,对不上立即停止(没输完不算输错);只有第一位没生效时会重来,最多 3 轮。
- 整串输完手机仍然锁着,就**立即停用**自动解锁并推送通知,不会第二次再试,因此不会累计输错触发抹掉数据。
- 手机重启后第一次解锁(BFU)必须人工完成,自动解锁不处理。
+- 手机横放充电时会进入**待机显示**,那个界面调不出密码键盘,自动解锁会失败。开启自动解锁时,在「设置 → 待机显示」里把它关掉。
## 停用后恢复
diff --git a/website/guide/configuration.md b/website/guide/configuration.md
index 43f077d..6285983 100644
--- a/website/guide/configuration.md
+++ b/website/guide/configuration.md
@@ -5,6 +5,7 @@
- **Docker**:写在仓库目录的 `.env`(从 `.env.example` 复制),改完 `docker compose up -d` 重建容器。
- **只写 compose 文件**:写在 `compose.yaml` 的 `environment:` 里(或同目录的 `.env` 加 `env_file`),改完同样 `docker compose up -d`。
- **从源码运行**:写在 `~/.config/iphone-control/env`(systemd 用户服务会读),改完 `systemctl --user restart iphone-control`。
+- **macOS**:同样写在 `~/.config/iphone-control/env`,启动守护进程前加载,改完重启守护进程,见 [macOS](../deploy/macos#配置)。
## 常用
diff --git a/website/guide/getting-started.md b/website/guide/getting-started.md
index ccca680..0b68f20 100644
--- a/website/guide/getting-started.md
+++ b/website/guide/getting-started.md
@@ -1,6 +1,6 @@
# 快速开始
-用 Docker 部署,大约 15 分钟。不用 Docker 见[从源码 / 二进制](../deploy/source)。
+在 Linux 上用 Docker 部署,大约 15 分钟。不用 Docker 见[从源码 / 二进制](../deploy/source);用 Mac 的话见 [macOS](../deploy/macos),安装向导和接入客户端的步骤与这里相同。
## 准备
@@ -10,7 +10,7 @@
- 主机能访问苹果服务器和 GitHub;国内网络一般要配代理
::: warning 一部手机只接一份
-不要同时运行两份 iphone-control,或其他基于 usbmuxd 的工具(go-ios、pymobiledevice3 等)连同一部手机。宿主机装了 usbmuxd 的,先 `sudo systemctl mask usbmuxd`。
+不要同时运行两份 iphone-control,或其他基于 usbmuxd 的工具(go-ios、pymobiledevice3 等)连同一部手机。Linux 宿主机装了 usbmuxd 的,先 `sudo systemctl mask usbmuxd`。
:::
## 1. 启动
diff --git a/website/guide/mcp-clients.md b/website/guide/mcp-clients.md
index 3e259a1..7e7ab4e 100644
--- a/website/guide/mcp-clients.md
+++ b/website/guide/mcp-clients.md
@@ -38,6 +38,8 @@ claude mcp add iphone -s user -- docker exec -i iphone-control iphone-control mc
}
```
+macOS 上没有 `XDG_RUNTIME_DIR`,socket 在 `~/.local/share/iphone-control/ctl.sock`,同样以 `mcp-config` 打印的为准。Claude Desktop 的配置文件在 `~/Library/Application Support/Claude/claude_desktop_config.json`。
+
::: warning 客户端和守护进程要在同一台机器上
MCP 服务经本机的 Unix socket 找守护进程。客户端在另一台电脑上时,用 SSH 拉起,例如 `"command": "ssh", "args": ["主机", "docker", "exec", "-i", "iphone-control", "iphone-control", "mcp"]`。
:::
diff --git a/website/guide/security.md b/website/guide/security.md
index 363111a..1dc99d9 100644
--- a/website/guide/security.md
+++ b/website/guide/security.md
@@ -10,7 +10,7 @@ iphone-control 本质上是一个手机遥控器:能访问它的人,就能
| Apple ID 会话、开发签名私钥 | 数据目录 `account/` | 能读数据目录的人。Apple ID 密码本身不保存 |
| 配对记录 | 数据目录 `lockdown/`(容器) | 能读数据目录的人;拿到它不用再点「信任」就能经 USB 访问手机 |
| 锁屏密码(仅开启自动解锁时) | 数据目录 `secrets/passcode`,**明文** | 能读数据目录的人 |
-| 通知密钥 | `.env` 或 systemd 环境文件 | 能读这个文件的人 |
+| 通知密钥 | `.env` 或 `~/.config/iphone-control/env` | 能读这个文件的人 |
## 默认的保护
diff --git a/website/guide/what-is-iphone-control.md b/website/guide/what-is-iphone-control.md
index 15572cc..c9432f9 100644
--- a/website/guide/what-is-iphone-control.md
+++ b/website/guide/what-is-iphone-control.md
@@ -1,13 +1,13 @@
# 什么是 iphone-control?
-iphone-control 让 AI agent(例如 Claude)操作一台用数据线接在 Linux 主机上的真实 iPhone:看屏幕、点按钮、输入文字、打开 App,就像人拿着手机一样。
+iphone-control 让 AI agent(例如 Claude)操作一台用数据线接在 Linux 主机或 Mac 上的真实 iPhone:看屏幕、点按钮、输入文字、打开 App,就像人拿着手机一样。
它以 [MCP](https://modelcontextprotocol.io)(Model Context Protocol)工具的形式提供能力,支持 MCP 的客户端(Claude Code、Claude Desktop、Cursor 等)都能直接用。
## 能用来做什么
- 让 agent 在手机上完成任务:查信息、填表、改设置、玩游戏。
-- 在真机上测试自己的 App 或网页,不需要 Mac。
+- 在真机上测试自己的 App 或网页;用 Linux 主机就行,不需要 Mac。
- 把一台闲置 iPhone 变成可以远程脚本化的设备。
## 怎么工作
@@ -18,15 +18,15 @@ iphone-control 让 AI agent(例如 Claude)操作一台用数据线接在 Lin
- **守护进程**常驻,独占手机:配对、挂载开发者镜像、建立隧道,在手机上运行 [WebDriverAgent](https://github.com/appium/WebDriverAgent)(WDA,苹果 XCTest 自动化框架上的代理),用它读界面、点击和输入。
- **MCP 服务**由 AI 客户端按需拉起,只是把工具调用转给守护进程。
- WDA 用你的**免费 Apple ID** 签名。免费签名 7 天过期,守护进程会在到期前自动重签。
-- WDA 不可用时(例如正在重启),点击、滑动、按键和截图改走 CoreDevice HID,照样能用。
+- WDA 不可用时(例如正在重启),点击、滑动、按键和截图改走 CoreDevice HID,照样能用(要 iOS 27 及以上)。
## 兼容性
| | |
|---|---|
-| 主机 | Linux,x86_64 或 arm64;Docker(Compose v2),或 Rust 1.88+ 从源码编译 |
-| 手机 | iOS 17 及以上 |
-| 已在真机验证 | iPhone 15 Pro Max,iOS 27.0.1 |
+| 主机 | Linux,x86_64 或 arm64:Docker(Compose v2),或 Rust 1.88+ 从源码编译<br>macOS,Apple Silicon:Rust 1.88+ 从源码编译,见 [macOS](../deploy/macos) |
+| 手机 | iOS 17 及以上;HID 后备路线要 iOS 27 及以上 |
+| 已在真机验证 | iPhone 15 Pro Max,iOS 27.0.1(Linux、macOS)<br>iPhone 12 mini,iOS 26.4.1(Linux) |
| 账号 | 免费 Apple ID 即可,建议专门注册一个 |
其他机型和 iOS 版本应该也能用,但还没测过,欢迎[反馈](https://github.com/Derrors/iphone-control/issues)。
diff --git a/website/index.md b/website/index.md
index 04707f9..1bf7587 100644
--- a/website/index.md
+++ b/website/index.md
@@ -4,7 +4,7 @@ layout: home
hero:
name: iphone-control
text: 让 AI agent 操作真实的 iPhone
- tagline: 在 Linux 上通过 USB 控制 iPhone,以 MCP 工具交给 Claude 等 AI。不需要 Mac,不需要付费开发者账号。
+ tagline: 在 Linux 或 Mac 上通过 USB 控制 iPhone,以 MCP 工具交给 Claude 等 AI。不需要 Xcode,不需要付费开发者账号。
image:
src: /logo.svg
alt: iphone-control
@@ -23,15 +23,15 @@ features:
- icon: 🤖
title: 给 AI 用的工具
details: 截图、读屏幕元素、按文字点击、滑动、输入中文、启动 App、等页面加载、一次执行多步,共 15 个 MCP 工具
- - icon: 🐧
- title: 只要一台 Linux
- details: 不需要 Mac 和 Xcode,用免费 Apple ID 给 WebDriverAgent 签名,7 天到期前自动重签
+ - icon: 💻
+ title: Linux 或 Mac 都行
+ details: Linux 上不需要 Mac,Mac 上不需要 Xcode。用免费 Apple ID 给 WebDriverAgent 签名,7 天到期前自动重签
- icon: 🔁
title: 自己维持运行
details: 自动配对、挂载开发者镜像、拉起 WDA;拔插、重启、WDA 崩溃后自动恢复
- icon: 🛟
title: 后备路线
- details: WDA 不可用时,点击、滑动、按键、截图仍可经 CoreDevice HID 完成
+ details: WDA 不可用时,点击、滑动、按键、截图仍可经 CoreDevice HID 完成(iOS 27 起)
- icon: 🔔
title: 需要你时会通知
details: 重签失败、Apple ID 会话失效、重启后要输密码、手机离线时,经 Bark 或 Telegram 推送
@@ -40,7 +40,7 @@ features:
details: WDA 经 usbmuxd 直连手机,本机不监听任何网络端口;自动解锁默认关闭
- icon: 📦
title: 一个二进制
- details: Rust 编写,Docker 一条命令部署,也可以从源码或预编译二进制运行
+ details: Rust 编写,Linux 上 Docker 一条命令部署,也可以从源码或预编译二进制运行;Mac 上从源码编译
- icon: 🧭
title: 省往返
details: 操作可以顺带返回操作后的界面,自动等界面稳定、识别加载中和挡路的弹窗
diff --git a/website/troubleshoot/faq.md b/website/troubleshoot/faq.md
index ddeb355..0e341f6 100644
--- a/website/troubleshoot/faq.md
+++ b/website/troubleshoot/faq.md
@@ -11,7 +11,7 @@ iphone-control doctor # 逐层检查,每项失败都给出修复办法
| `status` 显示 | 含义 | 怎么办 |
|---|---|---|
-| 手机未连接 | usbmuxd 看不到手机 | 检查数据线、解锁手机;宿主机装了 usbmuxd 时 `sudo systemctl mask usbmuxd` |
+| 手机未连接 | usbmuxd 看不到手机 | 检查数据线、解锁手机;Linux 宿主机装了 usbmuxd 时 `sudo systemctl mask usbmuxd` |
| 未配对 | 没有配对记录 | 运行 `setup`,手机上点「信任」 |
| 开发者模式未打开 | — | 运行 `setup`,按提示在手机上打开 |
| 手机锁屏,隧道建不起来 | 重启后还没解锁过 | 手动解锁一次 |
@@ -27,6 +27,8 @@ iphone-control doctor # 逐层检查,每项失败都给出修复办法
- **别的工具占着手机:** 同时运行 go-ios、pymobiledevice3 等会冲突。
- **数据线:** 有的线只能充电。`lsusb` 里看不到 Apple 设备(`05ac`)时换根线或换个口。
- **拔插后:** Docker 部署大约 1 分钟内自动恢复。
+- **充电时大约每分钟断开一次:** 手机开着「设置 → 电池 → 充电 → 80% 上限」时,在 80% 附近反复开始、停止充电,每次 USB-C 重新协商供电都会让 USB 断开 3~5 秒。用来做自动化的手机把上限改成 100%。
+- **Mac 上:** 不能用 Docker(没有 USB 直通),见 [macOS](../deploy/macos)。usbmuxd 是系统自带的,`doctor` 报连不上时运行 `sudo launchctl kickstart -k system/com.apple.usbmuxd`。
## WDA 起不来