运行expo start --dev-client时iOS真机无法连接的问题求助
问题描述
使用Xcode在iOS真机上构建应用后,启动页正常显示。执行命令npx expo start --dev-client,扫描生成的二维码后Safari打开链接http://localhost:8081,提示**"Safari无法打开页面,因为无法连接到服务器"**。按下r键重载时,控制台提示:
warn: No apps connected. Sending "reload" to all React Native apps failed. Make sure your app is running in the simulator or on a phone connected via USB.
电脑与iOS设备已连接同一Wi-Fi,iOS模拟器上运行正常,寻求可行解决方案。
环境信息
包版本
"@expo-google-fonts/baskervville": "^0.2.3", "@expo-google-fonts/mulish": "^0.2.3", "@kanelloc/react-native-animated-header-scroll-view": "^0.12.0", "@react-navigation/drawer": "^6.6.2", "@react-navigation/native": "6.1.1", "@react-navigation/native-stack": "6.9.7", "@tamagui/animations-reanimated": "1.5.19", "@tamagui/font-inter": "1.5.19", "@tamagui/lucide-icons": "1.5.19", "@tamagui/shorthands": "1.5.19", "@tamagui/theme-base": "1.5.19", "add": "^2.0.6", "expo": "~47.0.12", "expo-av": "~13.0.3", "expo-dev-client": "2.1.6", "expo-font": "11.0.1", "expo-linear-gradient": "12.0.1", "expo-speech": "~11.0.0", "expo-splash-screen": "~0.17.5", "expo-status-bar": "~1.4.2", "expo-updates": "~0.15.6", "react": "18.1.0", "react-dom": "18.1.0", "react-native": "0.70.5", "react-native-gesture-handler": "2.9.0", "react-native-lightbox-v2": "^0.9.0", "react-native-reanimated": "2.14.4", "react-native-safe-area-context": "4.4.1", "react-native-screens": "3.18.2", "react-native-shadow-2": "^7.0.6", "react-native-svg": "13.4.0", "react-native-timeline-flatlist": "^0.8.0", "react-native-web": "0.18.10", "tamagui": "1.5.19", "yarn": "^1.22.19"
Expo工作流
bare
系统环境
System: OS: macOS 12.5.1 Shell: 5.8.1 - /bin/zsh Binaries: Node: 19.8.1 - /opt/homebrew/bin/node Yarn: 3.2.0 - ~/Documents/dev/maison-des-geants/node_modules/.bin/yarn npm: 8.19.4 - ~/Documents/dev/maison-des-geants/node_modules/.bin/npm Managers: CocoaPods: 1.12.0 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1 IDEs: Android Studio: 2022.1 AI-221.6008.13.2211.9619390 Xcode: 14.2/14C18 - /usr/bin/xcodebuild npmPackages: expo: ~47.0.12 => 47.0.13 react: 18.1.0 => 18.1.0 react-dom: 18.1.0 => 18.1.0 react-native: 0.70.5 => 0.70.5 react-native-web: 0.18.10 => 0.18.10 Expo Workflow: bare
解决方案
替换localhost为电脑局域网IP启动服务
真机无法解析电脑的localhost,需用局域网IP启动:- 终端执行
ifconfig | grep inet,找到你的局域网IP(如192.168.1.100,排除127.0.0.1) - 执行命令:
npx expo start --dev-client --host 192.168.1.100(替换为你的IP) - 扫描新二维码,链接会指向你的IP,真机可正常连接
- 终端执行
信任开发者证书
- iOS设备打开「设置」→「通用」→「VPN与设备管理」
- 找到你的开发者账号,点击「信任」
- 重启已安装的应用
检查防火墙与端口占用
- 临时关闭电脑防火墙,测试是否能连接
- 终端执行
lsof -i :8081检查端口占用,如有进程,用kill -9 <PID>杀死后重启服务
USB连接真机启动
- 用USB线连接iOS设备到电脑,确保Xcode识别设备
- 执行
npx expo start --dev-client --localhost,通过USB隧道连接 - 打开应用,自动连接dev-server
重置Expo缓存
- 执行
npx expo start --dev-client --clear清除缓存 - 删除iOS设备上的应用,用Xcode重新构建安装
- 执行
检查expo-updates配置
- 打开
app.json,确认expo.updates.url配置正确,若不需要OTA更新可暂时注释 - 重新用Xcode构建应用,让配置生效
- 打开
内容的提问来源于stack exchange,提问作者Achraf
相关产品推荐
相关产品推荐

