You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在iPhone/iPad实体设备上直接运行Flutter应用?

Flutter iOS实体设备运行必备手动配置
  • 签名与账号配置
    打开Xcode加载项目ios目录下的Runner.xcworkspace文件,选中左侧导航栏的Runner项目,进入「Signing & Capabilities」标签页:
    1. 勾选「Automatically manage signing」
    2. 选择已登录的Apple开发者账号(普通个人账号无需付费即可使用,单应用安装有效期为7天)
    3. 修改Bundle Identifier为全局唯一的自定义字符串,不可使用默认模板ID
  • 设备信任配置
    首次通过Xcode安装应用到实体设备后,打开iOS设备的「设置」-「通用」-「VPN与设备管理」,找到对应开发者证书,点击信任后才可正常启动应用。
  • 网络权限配置
    iOS 14及以上系统需要在项目ios/Runner/Info.plist文件中添加本地网络权限,否则debug模式下Flutter无法建立设备和开发机的通信链路,配置代码如下:
    <key>NSLocalNetworkUsageDescription</key>
    <string>需要本地网络权限用于debug模式下的应用调试</string>
    
VM Service连接超时问题解决方案

报错截图:
报错截图
控制台输出日志原文:

Running Xcode build...
Xcode build done.                                           20.6s
Installing and launching...
Connecting to the VM Service is taking longer than expected...
Still attempting to connect to the VM Service...
If you do NOT see the Flutter application running, it might have crashed. The device logs (e.g. from adb or XCode) might have more details.
If you do see the Flutter application running on the device, try re-running with --host-vmservice-port to use a specific port known to be available.

日志中文翻译:

正在执行Xcode构建...
Xcode构建完成,耗时20.6秒
正在安装并启动应用...
连接VM Service的耗时超出预期...
仍在尝试连接VM Service...
如果未看到Flutter应用运行,可能已崩溃。设备日志(例如来自adb或XCode的日志)可能包含更多详细信息。
如果确实看到Flutter应用在设备上运行,尝试添加--host-vmservice-port参数指定已知可用的端口重新运行。

排查步骤:

  • 若应用安装后直接闪退/无法启动:打开Xcode的「Window」-「Devices and Simulators」,选中对应实体设备查看Crash日志,排查是否存在签名错误、架构不匹配、其他权限缺失问题。
  • 若应用可以正常启动但调试连接超时:
    1. 确保Mac和iOS设备连接在同一个WiFi局域网下,没有防火墙或网络策略拦截本地端口通信
    2. 运行时指定固定的VM Service端口,命令如下:
    flutter run -d 设备ID --host-vmservice-port 5555
    
  • 若仅debug模式无法连接,release模式可正常运行:判定为本地网络权限配置问题,完成上文Info.plist权限配置后重新运行即可,release模式不需要VM Service通信所以不受影响,可通过flutter run --release -d 设备ID验证该场景。

内容的提问来源于stack exchange,提问作者Jashwanth Neela

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.07 09:39:03