Open-AutoGLM icon indicating copy to clipboard operation
Open-AutoGLM copied to clipboard

Ios iphone

Open Rocke1001feller opened this issue 11 months ago • 14 comments

Summary

This PR introduces complete iOS support for Open-AutoGLM, enabling AI-powered automation on iPhone devices via WebDriverAgent (WDA).

Total changes: 14 files

  • 🆕 New modules: iOS agent, WDA wrapper, action handler
  • 📚 Documentation: Comprehensive setup guide (895 lines)
phone_agent/
├── wda/              # WebDriverAgent wrapper (814 lines)
│   ├── client.py     # HTTP client with session management
│   ├── device.py     # Device control (tap, swipe, app launch)
│   ├── [input.py](http://_vscodecontentref_/3)      # Text input with UI trigger
│   └── screenshot.py # Screenshot capture with scale handling
├── actions/
│   └── [handler_ios.py](http://_vscodecontentref_/4) # iOS action handler (345 lines)
├── agent_ios.py      # iOS automation agent (251 lines)
└── config/
    └── apps_ios.py   # iOS app bundles (212 lines)

What This PR Introduces

🎯 Core Features

  1. iOS Automation Engine (phone_agent/wda/)

    • HTTP client for WebDriverAgent communication
    • Device control: tap, swipe, scroll, keyboard operations
    • Screenshot capture with automatic coordinate system conversion
    • Text input with UI state synchronization
  2. iOS-Specific Action Handler (phone_agent/actions/handler_ios.py)

    • Implements all AutoGLM actions (Tap, Type, Swipe, etc.)
    • Coordinate conversion: relative (model) ↔ absolute (device)
    • App launching via bundle identifiers
    • Sensitive operation confirmation mechanism
  3. iOS Agent (phone_agent/agent_ios.py)

    • Complete workflow integration
    • Screenshot preprocessing and model communication
    • Multi-step task execution with thinking process logging
  4. iOS Entry Point (main_ios.py)

    • Device connection verification (WDA, screenshot, app detection)
    • Model API validation
    • Command-line interface for automation tasks

Breaking Changes

None - This PR is purely additive:

New iOS-specific modules (phone_agent/wda/, agent_ios.py)

New entry point (main_ios.py) Android functionality remains unchanged

how to use

  • For New iOS Users
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up WebDriverAgent (see iOS_SETUP_GUIDE.md):
# Build and run WDA on device
xcodebuild -project WebDriverAgent.xcodeproj ...

# Forward port
iproxy 8100:8100
  1. Run iOS automation:
python main_ios.py \
    --base-url https://open.bigmodel.cn/api/paas/v4 \
    --model autoglm-phone \
    --apikey YOUR_API_KEY \
   "打匀埮信发送䞀䞪笑话给文件䌠蟓助手"
  • For Existing Android Users No changes required - Android functionality is unaffected. Continue using main.py as before.

https://www.bilibili.com/video/BV1wLmDBwEDj/?pop_share=1&vd_source=348fbd7b0b94d0ab5ee9f3f1b2ff2950

Rocke1001feller avatar Dec 13 '25 00:12 Rocke1001feller

Open-AutoGLM iOS 适配指南

本文档诎明劂䜕圚 iOS 讟倇䞊运行 Open-AutoGLM Phone Agent。

📋 前眮条件

  1. WebDriverAgent 已就绪

    • 确保 WDA 已圚 iOS 讟倇䞊启劚通过Xcode运行
    • 获取 WDA URL通垞䞺 http://localhost:8100通过USB蜬发
  2. 暡型服务已启劚

    • 可以䜿甚本地郚眲或第䞉方服务智谱BigModel、Novita等

⚠ 重芁USB端口蜬发

由于iOS安党限制WiFi盎连WDA通垞䌚被阻断。掚荐䜿甚USB端口蜬发

# 安装 libimobiledevice劂未安装
brew install libimobiledevice

# 启劚端口蜬发圚单独的终端窗口运行保持运行
iproxy 8100 8100

# 现圚可以通过 http://localhost:8100 访问WDA

🚀 快速匀始

1. 安装䟝赖

cd Open-AutoGLM
pip install -r requirements.txt
pip install -e .

2. 启劚USB端口蜬发

# 终端窗口1 - 保持运行
iproxy 8100 8100

3. 检查 WDA 连接

# 终端窗口2
python main_ios.py --check-only
# 或明确指定URL
python main_ios.py --wda-url http://localhost:8100 --check-only

4. 运行 iOS Agent

# 䜿甚智谱BigModel
python main_ios.py \
    --base-url https://open.bigmodel.cn/api/paas/v4 \
    --model autoglm-phone \
    --apikey YOUR_API_KEY \
    "打匀小红乊搜玢矎食"

# 亀互暡匏
python main_ios.py \
    --base-url https://open.bigmodel.cn/api/paas/v4 \
    --model autoglm-phone \
    --apikey YOUR_API_KEY

4. 查看支持的 iOS App

python main_ios.py --list-apps

📁 项目结构

phone_agent/
├── adb/              # Android ADB 实现原有
├── wda/              # iOS WebDriverAgent 实现新增
│   ├── __init__.py   # 富出接口
│   ├── client.py     # HTTP 客户端
│   ├── device.py     # 讟倇操䜜tap/swipe/home等
│   ├── input.py      # 文本蟓入
│   └── screenshot.py # 截囟
├── actions/
│   ├── handler.py    # Android Action Handler
│   └── handler_ios.py # iOS Action Handler新增
├── agent.py          # Android Agent
├── agent_ios.py      # iOS Agent新增
└── config/
    └── apps_ios.py   # iOS App Bundle ID 映射新增

🔌 启劚 WebDriverAgent

方法1: 通过 Xcode

xcodebuild -project WebDriverAgent.xcodeproj \
           -scheme WebDriverAgentRunner \
           -destination 'id=YOUR_DEVICE_UDID' \
           test

方法2: 查看讟倇 UDID

# 暡拟噚
xcrun simctl list devices available

# 真机
xcrun xctrace list devices

获取 WDA URL

启劚后圚日志䞭查扟

ServerURLHere->http://[DEVICE_IP]:8100<-ServerURLHere

⚠ iOS 侎 Android 的差匂

功胜 Android iOS
返回 物理/虚拟Back键 巊蟹猘滑劚或点击巊䞊角返回
键盘 需芁ADB Keyboard 䜿甚原生键盘
启劚App 通过包名 通过Bundle ID
截囟 ADB screencap WDA /screenshot

🛠 垞见问题

WDA 连接倱莥

  1. 确保讟倇和电脑圚同䞀眑络
  2. 检查 WDA 是吊正垞运行
  3. 确讀防火墙没有阻止 8100 端口

截囟倱莥

  1. 可胜是敏感界面劂支付页面
  2. WDA 䌚返回黑色占䜍囟

App 启劚倱莥

  1. 检查 apps_ios.py 䞭是吊有该 App 的 Bundle ID
  2. 可以手劚添加新 App 的映射

📝 添加新 App 支持

猖蟑 phone_agent/config/apps_ios.py

IOS_APP_PACKAGES = {
    # 添加新 App
    "新App䞭文名": "com.example.bundleid",
    "NewAppEnglish": "com.example.bundleid",
    ...
}

🔗 盞关铟接

Rocke1001feller avatar Dec 13 '25 07:12 Rocke1001feller

Open-AutoGLM iOS 完敎郚眲指南诊情版

最后曎新: 2025幎12月13日

本指南诊细记圕了 Open-AutoGLM 圚 iOS 平台的完敎适配过皋包括遇到的所有问题和解决方案。


📋 目圕

  • 1. 抂述
  • 2. 环境准倇
  • 3. WebDriverAgent 郚眲
  • 4. USB 端口蜬发
  • 5. 安装 Open-AutoGLM
  • 6. 运行测试
  • 7. 栞心技术问题䞎解决方案
  • 8. 垞见问题
  • 9. 匹窗倄理

1. 抂述

1.1 项目背景

Open-AutoGLM 是基于 AutoGLM-Phone-9B 视觉-语蚀暡型的智胜手机自劚化框架。本项目成功将其从 Android (ADB) 适配到 iOS (WebDriverAgent)。

1.2 技术架构

┌─────────────────────────────────────────────────────────┐
│                  AutoGLM-Phone-9B 暡型                   │
│              (视觉-语蚀暡型理解屏幕并决策)              │
└─────────────────────────────────────────────────────────┘
                            ↓
┌─────────────────────────────────────────────────────────┐
│                   Open-AutoGLM Agent                     │
│        agent_ios.py + handler_ios.py (任务执行噚)        │
└─────────────────────────────────────────────────────────┘
                            ↓
┌─────────────────────────────────────────────────────────┐
│                   WDA Python 封装层                      │
│     phone_agent/wda/ (HTTP 客户端 + 坐标蜬换)           │
└─────────────────────────────────────────────────────────┘
                            ↓
┌─────────────────────────────────────────────────────────┐
│              WebDriverAgent (HTTP Server)                │
│            运行圚 iOS 讟倇䞊监听 8100 端口             │
└─────────────────────────────────────────────────────────┘
                            ↓
┌─────────────────────────────────────────────────────────┐
│            iproxy (USB 端口蜬发工具)                     │
│         将 Mac 的 8100 蜬发到 iPhone 的 8100            │
└─────────────────────────────────────────────────────────┘
                            ↓
┌─────────────────────────────────────────────────────────┐
│                   iOS 讟倇 (真机)                        │
│                   执行实际操䜜                           │
└─────────────────────────────────────────────────────────┘

1.3 iOS vs Android 差匂

特性 Android (ADB) iOS (WDA)
通信协议 ADB Shell 呜什 HTTP REST API
坐标系统 Pixels (像玠) Points (逻蟑点) ⚠
猩攟因子 1x 2x/3x (Retina)
截囟 adb shell screencap GET /screenshot
点击 input tap x y POST /wda/tap
文字蟓入 ADB Keyboard 原生键盘 + /wda/keys
返回键 物理 Back 键 巊蟹猘滑劚手势
连接方匏 USB 盎连 USB + iproxy 蜬发 ⚠

2. 环境准倇

2.1 系统芁求

  • 操䜜系统: macOS 10.14+ (建议 macOS 12+)
  • Xcode: 14.0+ (需芁从 App Store 安装)
  • iOS 讟倇: iOS 13.0+ (建议 iOS 14+)
  • Python: 3.10+
  • 眑络: 皳定的互联眑连接甚于 AI 暡型 API

2.2 安装必芁工具

2.2.1 安装 Homebrew劂未安装

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2.2.2 安装 libimobiledevice

brew install libimobiledevice

䜜甚: 提䟛 iproxy 等工具甚于 USB 端口蜬发。

2.2.3 验证安装

# 验证 iproxy
which iproxy
# 应蟓出: /usr/local/bin/iproxy 或 /opt/homebrew/bin/iproxy

# 检查连接的 iOS 讟倇
idevice_id -l
# 应蟓出讟倇的 UDID

3. WebDriverAgent 郚眲

3.1 克隆 WebDriverAgent

本项目已包含 WebDriverAgent䜍于

/path/to/Open-AutoGLM/WebDriverAgent/

劂果需芁单独安装

git clone https://github.com/appium/WebDriverAgent.git
cd WebDriverAgent
./Scripts/bootstrap.sh

3.2 配眮 Xcode 项目

步骀 1: 打匀项目

open WebDriverAgent/WebDriverAgent.xcodeproj

步骀 2: 配眮筟名

  1. 圚 Xcode 巊䟧项目富航噚䞭选择 WebDriverAgent 项目
  2. 选择 WebDriverAgentLib target
  3. 点击 Signing & Capabilities 标筟
  4. 募选 Automatically manage signing
  5. 选择䜠的 Team需芁 Apple Developer 莊号

重芁: 重倍䞊述步骀䞺以䞋 targets 配眮筟名

  • WebDriverAgentLib
  • WebDriverAgentRunner
  • IntegrationApp

步骀 3: 修改 Bundle ID劂果遇到冲突

劂果出现 "Failed to register bundle identifier" 错误

  1. 选择 WebDriverAgentRunner target
  2. 修改 Bundle Identifier䟋劂
    com.yourname.WebDriverAgentRunner
    

3.3 郚眲到讟倇

步骀 1: 连接 iOS 讟倇

  1. 䜿甚 USB 线连接 iPhone/iPad 到 Mac
  2. 圚讟倇䞊信任歀电脑
  3. 圚 Xcode 顶郚工具栏选择䜠的真机讟倇

步骀 2: 运行 WebDriverAgent

  1. 选择 Product → Scheme → WebDriverAgentRunner
  2. 按 ⌘+U 或点击 Product → Test

步骀 3: 信任匀发者銖次运行

劂果讟倇䞊出现"䞍受信任的匀发者"譊告

  1. 圚 iOS 讟倇䞊打匀 讟眮 → 通甹 → VPN䞎讟倇管理
  2. 扟到䜠的匀发者莊号
  3. 点击信任

步骀 4: 验证 WDA 启劚

圚 Xcode Console 䞭查扟以䞋日志

ServerURLHere->http://192.168.x.x:8100<-ServerURLHere

记䞋这䞪 IP 地址䜆我们䌚䜿甚 USB 蜬发䞍盎接䜿甚 WiFi IP。


4. USB 端口蜬发

4.1 䞺什么需芁 iproxy

栞心问题: iOS 的安党限制䜿埗 WiFi 盎连 WDA 䞍皳定䞔经垞被阻断。

解决方案: 䜿甚 USB 端口蜬发将 Mac 的本地端口映射到 iPhone 的端口。

4.2 启劚 iproxy

圚单独的终端窗口运行需芁保持运行

iproxy 8100 8100

蟓出瀺䟋

Creating listening port 8100 for device port 8100
waiting for connection

关键点

  • ✅ 歀呜什需芁持续运行䞍芁关闭终端
  • ✅ 劂果看到 "waiting for connection"诎明正垞
  • ✅ 建议圚 tmux/screen 䞭运行或䜿甚后台进皋

4.3 验证连接

圚及䞀䞪终端运行

curl http://localhost:8100/status

成功蟓出JSON栌匏

{
  "value": {
    "message": "WebDriverAgent is ready to accept commands",
    "state": "success",
    ...
  },
  "sessionId": "...",
  "status": 0
}

倱莥情况

curl: (7) Failed to connect to localhost port 8100: Connection refused

解决方法

  1. 确讀 iproxy 正圚运行
  2. 确讀 WDA 圚 Xcode 䞭正圚运行Test 状态
  3. 检查讟倇是吊通过 USB 连接

5. 安装 Open-AutoGLM

5.1 克隆仓库

git clone https://github.com/Rocke1001feller/Open-AutoGLM.git
cd Open-AutoGLM
git checkout iOS-iPhone

5.2 创建虚拟环境

python3 -m venv .venv
source .venv/bin/activate

5.3 安装䟝赖

pip install -r requirements.txt
pip install -e .

5.4 验证安装

python main_ios.py --check-only

成功蟓出

🔍 Checking iOS device connection...
--------------------------------------------------
1. Checking WDA connectivity (http://localhost:8100)... ✅ OK
2. Checking screenshot capability... ✅ OK (1170x2532)
3. Checking active app detection... ✅ OK (Current: SpringBoard)
--------------------------------------------------
✅ iOS device connection OK!

6. 运行测试

6.1 配眮 API Key

获取智谱 AI API Keyhttps://open.bigmodel.cn

6.2 运行基础任务

python main_ios.py \
    --base-url https://open.bigmodel.cn/api/paas/v4 \
    --model autoglm-phone \
    --apikey "YOUR_API_KEY" \
    "打匀矎团搜玢附近的火锅"

6.3 查看支持的 App

python main_ios.py --list-apps

6.4 亀互暡匏

python main_ios.py \
    --base-url https://open.bigmodel.cn/api/paas/v4 \
    --model autoglm-phone \
    --apikey "YOUR_API_KEY"

然后蟓入任务䟋劂

  • "打匀埮信发送䞀䞪笑话给文件䌠蟓助手"
  • "打匀淘宝搜玢 iPhone 15"
  • "打匀矎团搜玢附近的刀削面銆并䜜掚荐"

7. 栞心技术问题䞎解决方案

7.1 坐标系统问题最关键

问题描述

圚初始实现䞭点击䜍眮䞥重偏移通垞偏移 3 倍距犻。

根本原因

WDA 䜿甚 Points逻蟑点 坐标系统而䞍是 Pixels像玠。

iOS 坐标系统诊解

iPhone 讟倇瀺䟋iPhone 14 Pro

物理屏幕分蟚率Pixels: 1179 × 2556
逻蟑分蟚率Points:      393 × 852
猩攟因子Scale:          3.0x

关系: Pixels = Points × Scale

错误的实现

# ❌ 盎接发送像玠坐标
client.post("/wda/tap", {"x": 589, "y": 1278})  # 像玠坐标

# WDA 理解䞺: 589 points = 1767 pixels
# 实际想点击的䜍眮: 589 pixels = 196 points
# 结果: 点击䜍眮偏移 3 倍

正确的实现

# ✅ 蜬换䞺点坐标
SCALE_FACTOR = 3.0  # iPhone @3x

x_pixels = 589
y_pixels = 1278

x_points = x_pixels / SCALE_FACTOR  # 196.3
y_points = y_pixels / SCALE_FACTOR  # 426.0

client.post("/wda/tap", {"x": x_points, "y": y_points})

解决方案

文件: phone_agent/wda/device.py

# 添加劚态获取 scale factor
def _get_scale_factor(device_id: str | None = None) -> float:
    """劚态获取讟倇的 scale factor"""
    try:
        client = get_client(device_id)
        resp = client.get("/wda/screen", use_session=False)
        value = resp.get("value", {})
        return float(value.get("scale", 3.0))
    except:
        return 3.0  # 默讀 @3x

# 添加坐标蜬换凜数
def _pixels_to_points(x: int, y: int, device_id: str | None = None) -> tuple[float, float]:
    """将像玠坐标蜬换䞺点坐标"""
    scale = _get_scale_factor(device_id)
    return x / scale, y / scale

# 修改所有坐标盞关凜数
def tap(x: int, y: int, device_id: str | None = None, delay: float = 0.5) -> None:
    client = get_client(device_id)
    x_pt, y_pt = _pixels_to_points(x, y, device_id)
    client.post("/wda/tap", {"x": x_pt, "y": y_pt})
    time.sleep(delay)

修改涉及的凜数

  • tap() - 点击
  • double_tap() - 双击
  • long_press() - 长按
  • swipe() - 滑劚
  • back() - 返回手势

参考资料

  • 权嚁来源: WebDriverAgent 源码

    • 文件: WebDriverAgentLib/Commands/FBElementCommands.m
    • 行号: 658-685
    • 关键代码: coordinateWithOffset: 䜿甚的是 Points
  • 成功案䟋: gekowa/Open-AutoGLM ios-support-3 分支

    • 䜿甚 SCALE_FACTOR = 3 进行蜬换
    • 所有坐标操䜜郜陀以 scale factor

7.2 文字蟓入问题

问题描述

初期文字蟓入无效键盘匹出后无法蟓入文字。

根本原因

  1. iOS 䞍需芁像 Android 那样安装 ADB Keyboard
  2. 需芁䜿甚党局 /wda/keys 端点而䞍是元玠特定的蟓入
  3. 文本栌匏需芁是字笊数组 list(text)

解决方案

文件: phone_agent/wda/input.py

def type_text(text: str, device_id: str | None = None, frequency: int = 60) -> None:
    """䜿甚党局键盘蟓入文本"""
    if not text:
        return
    
    client = get_client(device_id)
    
    # 发送字笊数组 + frequency 参数
    client.post("/wda/keys", {
        "value": list(text),  # 蜬换䞺字笊数组
        "frequency": frequency  # 打字速床
    }, use_session=True)

def clear_text(device_id: str | None = None) -> None:
    """枅陀蟓入框文本"""
    client = get_client(device_id)
    
    try:
        # 尝试获取激掻的元玠
        resp = client.get("/element/active", use_session=True)
        if "value" in resp:
            element_id = resp["value"].get("ELEMENT")
            if element_id:
                # 枅陀元玠
                client.post(f"/element/{element_id}/clear", use_session=True)
                return
    except:
        pass
    
    # 倇选方案发送退栌键
    backspace = "\u0008"
    client.post("/wda/keys", {
        "value": [backspace] * 100
    }, use_session=True)

def hide_keyboard(device_id: str | None = None) -> None:
    """隐藏键盘"""
    client = get_client(device_id)
    
    try:
        # 需芁䜿甚 session
        client.post("/wda/keyboard/dismiss", use_session=True)
    except:
        pass  # 応略错误键盘可胜已关闭

䞉步蟓入法 (handler_ios.py):

def _handle_type(self, action: dict, width: int, height: int) -> ActionResult:
    """倄理文字蟓入"""
    text = action.get("text", "")
    
    # 1. 枅陀现有文本
    clear_text(self.device_id)
    time.sleep(0.5)
    
    # 2. 蟓入新文本
    type_text(text, self.device_id, frequency=60)
    time.sleep(0.5)
    
    # 3. 隐藏键盘
    hide_keyboard(self.device_id)
    time.sleep(0.5)
    
    return ActionResult(True, False)

7.3 键盘隐藏 404 错误

问题描述

WDA POST /wda/keyboard/dismiss error: 404 Client Error

根本原因

/wda/keyboard/dismiss 端点需芁 session䜆初始实现䜿甚了 use_session=False。

证据

WebDriverAgent 源码 FBCustomCommands.m 第 43 行

[[FBRoute POST:@"/wda/keyboard/dismiss"] respondWithTarget:self 
    action:@selector(handleDismissKeyboardCommand:)],

泚意: 没有 .withoutSession 修饰笊诎明需芁 session。

解决方案

  1. 修改 input.py:

    # 改䞺䜿甚 session
    client.post("/wda/keyboard/dismiss", use_session=True)
    
  2. 修改 client.py - 添加到需芁 session 的路埄列衚:

    session_required_prefixes = [
        "/wda/tap", "/wda/keys", "/wda/swipe", 
        "/wda/keyboard",  # 新增
        # ...
    ]
    

7.4 Session 管理

问题描述

某些操䜜返回 404 错误因䞺 session 过期。

解决方案

文件: phone_agent/wda/client.py

def post(self, path: str, data: dict = None, use_session: bool = True, **kwargs) -> dict:
    """发送 POST 请求自劚倄理 session 过期"""
    original_path = path
    if use_session:
        path = self._session_path(path)
    url = f"{self.base_url}{path}"
    
    for attempt in range(2):  # 最倚重试 2 次
        try:
            resp = self._session.post(url, json=data or {}, timeout=self.timeout)
            
            # 检查 404可胜是 session 过期
            if resp.status_code == 404 and "/session/" in path and attempt == 0:
                # Session 过期重新创建
                self._invalidate_session()
                path = self._session_path(original_path)
                url = f"{self.base_url}{path}"
                continue  # 重试
            
            resp.raise_for_status()
            return resp.json()
        except Exception as e:
            if attempt == 0 and "/session/" in path:
                # 重试䞀次
                self._invalidate_session()
                continue
            return {"error": str(e)}
    
    return {"error": "Request failed after retry"}

8. 垞见问题

Q1: WDA 连接倱莥

错误信息:

Error: Cannot connect to WebDriverAgent.

解决步骀:

  1. 检查 iproxy 是吊运行:

    pgrep -f iproxy
    # 劂果没有蟓出诎明未运行
    
  2. 启劚 iproxy:

    iproxy 8100 8100
    
  3. 检查 WDA 是吊圚 Xcode 䞭运行:

    • 确讀 Xcode Console 星瀺 "ServerURLHere"
    • 确讀讟倇未锁屏
  4. 测试连接:

    curl http://localhost:8100/status
    

Q2: 坐标点击䞍准确

症状: 点击䜍眮偏移通垞偏移 3 倍

原因: 坐标蜬换问题

检查:

# 运行测试脚本
python test_wda_coordinates.py

验证修倍:

# 查看 device.py 是吊有坐标蜬换
grep "_pixels_to_points" phone_agent/wda/device.py

Q3: 文字蟓入无效

症状: 蟓入框聚焊䜆无文字蟓出

检查枅单:

  • [ ] 键盘是吊匹出
  • [ ] /wda/keys 端点是吊䜿甚 session
  • [ ] 文本栌匏是吊䞺 list(text)

调试:

# 查看日志䞭是吊有 keyboard 盞关错误
python main_ios.py ... 2>&1 | grep -i keyboard

Q4: 应甚启劚倱莥

错误: App not found: xxx

原因: Bundle ID 未配眮

解决:

猖蟑 phone_agent/config/apps_ios.py:

IOS_APP_PACKAGES = {
    "䜠的App名称": "com.example.bundleid",
    # ...
}

查扟 Bundle ID:

# 方法1: 通过 WDA 查看圓前应甚
curl http://localhost:8100/wda/activeAppInfo

# 方法2: 䜿甚 ideviceinstaller
ideviceinstaller -l

Q5: 截囟倱莥或黑屏

原因: 敏感界面支付、密码等

解决: 这是 iOS 安党特性无法绕过。系统䌚返回黑色占䜍囟。

Q6: USB 连接䞍皳定

症状: iproxy 频繁断匀

解决:

  1. 䜿甚原装 USB 线
  2. 曎换 USB 端口避免 USB hub
  3. 犁甚讟倇自劚锁屏
  4. 圚 iOS 讟眮䞭启甚"保持连接"

Q7: Xcode 筟名问题

错误: "Failed to create provisioning profile"

解决:

  1. 确保登圕 Apple IDXcode → Preferences → Accounts
  2. 修改 Bundle ID 䞺唯䞀倌
  3. 䜿甚免莹匀发者莊号7 倩有效期

9. 匹窗倄理

9.1 匹窗识别胜力

AutoGLM-Phone-9B 是视觉-语蚀暡型可以识别和倄理匹窗

✅ 可以识别:

  • 广告匹窗
  • 权限请求定䜍、通知、盞机等
  • 曎新提瀺
  • 掻劚掚广
  • 匕富页

✅ 可以执行:

  • 点击"关闭"、"X"按钮
  • 点击"取消"、"皍后再诎"
  • 点击"跳过"、"我知道了"
  • 点击匹窗倖区域关闭

9.2 系统提瀺䌘化

已圚系统提瀺词䞭添加匹窗䌘先倄理规则prompts_zh.py 第 1 条

"1. **匹窗倄理重芁**圚执行任务过皋䞭劂果屏幕䞊出现匹窗、广告、"
"通知请求、权限请求等干扰性界面应该䌘先关闭它们。垞见的关闭方匏"
"点击"关闭"、"X"、"取消"、"皍后再诎"、"跳过"等按钮或点击匹窗倖的区域。"
"关闭匹窗后再继续执行䞻任务。"

9.3 测试匹窗倄理

# 测试淘宝/京䞜等垞见匹窗
python main_ios.py \
    --base-url https://open.bigmodel.cn/api/paas/v4 \
    --model autoglm-phone \
    --apikey "YOUR_KEY" \
    "打匀淘宝搜玢 iPhone 15"

# 观察暡型是吊先关闭匹窗再执行搜玢

9.4 匹窗倄理流皋

┌─────────────────────────────────────┐
│ 1. 暡型看到屏幕包括匹窗          │
└─────────────────────────────────────┘
                  ↓
┌─────────────────────────────────────┐
│ 2. 刀断是吊有干扰性匹窗          │
│    - 检查是吊有"关闭"按钮            │
│    - 是吊遮挡䞻芁内容                │
│    - 是吊䞎任务无关                  │
└─────────────────────────────────────┘
                  ↓
         ┌────────┮────────┐
         │                 │
    【是】              【吊】
         │                 │
         ↓                 ↓
┌─────────────────┐  ┌─────────────────┐
│ 3. 点击关闭按钮 │  │ 继续执行䞻任务  │
└─────────────────┘  └─────────────────┘
         │
         ↓
┌─────────────────────────────────────┐
│ 4. 验证匹窗是吊关闭                  │
└─────────────────────────────────────┘
         │
         ↓
┌─────────────────────────────────────┐
│ 5. 继续执行䞻任务                    │
└─────────────────────────────────────┘

10. 总结

10.1 关键成就

✅ 成功适配 iOS 平台 - 从 Android ADB 迁移到 WebDriverAgent
✅ 解决坐标系统问题 - Points vs Pixelsscale factor 蜬换
✅ 实现文字蟓入 - å…šå±€ /wda/keys + 字笊数组栌匏
✅ 修倍 Session 管理 - 自劚重试和 session 恢倍
✅ 䌘化匹窗倄理 - 系统提瀺词䌘先级调敎

10.2 栞心技术决策

决策点 Android 方案 iOS 方案 理由
连接方匏 ADB USB 盎连 USB + iproxy 蜬发 iOS 安党限制 WiFi 䞍皳定
坐标系统 像玠坐标 点坐标÷scale WDA 䜿甚 Points 坐标系
文字蟓入 ADB Keyboard 原生键盘 + /wda/keys iOS 䞍支持虚拟键盘
返回操䜜 物理 Back 键 巊蟹猘滑劚手势 iOS 无返回键

10.3 螩过的坑

# 问题 初期错误 正确方案
1 坐标偏移 盎接䌠像玠坐标 陀以 scale factor
2 文字蟓入倱莥 尝试查扟元玠蟓入 䜿甚党局 /wda/keys
3 键盘隐藏 404 use_session=False use_session=True
4 WiFi 连接䞍皳定 盎接连讟倇 IP 䜿甚 iproxy USB 蜬发
5 Session 过期 单次请求无重试 自劚检测并重建 session

10.4 工具蜯件䟝赖

工具 䜜甚 安装呜什 必需性
iproxy USB 端口蜬发 brew install libimobiledevice ✅ 必需
Xcode 猖译运行 WDA App Store 安装 ✅ 必需
WebDriverAgent iOS 自劚化服务 已包含圚项目䞭 ✅ 必需
Python 3.10+ 运行 AutoGLM brew install [email protected] ✅ 必需

10.5 䞋䞀步䌘化方向

  • [ ] 支持倚讟倇并行控制
  • [ ] 䌘化截囟性胜圓前每步郜截囟
  • [ ] 增区匹窗识别准确率
  • [ ] 支持暡拟噚圓前仅真机
  • [ ] 添加圕屏功胜甚于调试
  • [ ] 支持曎倚 iOS 䞓属手势3D Touch、Control Center 等

附圕

A. 完敎测试枅单

# 1. 检查环境
which iproxy           # 应有蟓出
which python3          # 应有蟓出
xcodebuild -version    # 应星瀺 Xcode 版本

# 2. 启劚 iproxy
iproxy 8100 8100 &

# 3. 启劚 WDA圚 Xcode 䞭

# 4. 验证连接
curl http://localhost:8100/status

# 5. 运行测试
python main_ios.py --check-only
python test_wda_coordinates.py
python main_ios.py --list-apps

# 6. 执行任务
python main_ios.py \
    --base-url https://open.bigmodel.cn/api/paas/v4 \
    --model autoglm-phone \
    --apikey "YOUR_KEY" \
    "打匀埮信发送消息给文件䌠蟓助手"

B. 参考资料

C. 联系方匏

  • Issues: https://github.com/zai-org/Open-AutoGLM/issues
  • Pull Request: #156

文档版本: 1.0
䜜者: Rockefeller 最后曎新: 2025幎12月13日

Rocke1001feller avatar Dec 13 '25 07:12 Rocke1001feller

This is an awesome commit, so cool!

tigerjibo avatar Dec 13 '25 15:12 tigerjibo

有点 nb 哊

finger1517 avatar Dec 13 '25 15:12 finger1517

还可以

ianisme avatar Dec 15 '25 23:12 ianisme

已倍现 确实没问题给倧䜬打call

Scott-lzh avatar Dec 16 '25 02:12 Scott-lzh

是吊可以试试越狱后的手机

qb3468-creator avatar Dec 16 '25 10:12 qb3468-creator

只胜 macos么 windows操䜜ios可以么

jiek8557 avatar Dec 17 '25 07:12 jiek8557

没有苹果匀发者莊号胜搞么😂

zhuchao941 avatar Dec 18 '25 07:12 zhuchao941

倧䜬 这䞪必须芁MAC OS电脑吗

sucheng111 avatar Dec 19 '25 08:12 sucheng111

䜠奜可以实现真正的移劚而䞍是圚局域眑内么

StupidStudentInSchool avatar Dec 20 '25 08:12 StupidStudentInSchool

已倍现 倧䜬靠谱

alexwikk93-maker avatar Dec 20 '25 23:12 alexwikk93-maker

请问甚linux电脑怎么匄

bbbbbbbbly avatar Feb 03 '26 06:02 bbbbbbbbly