React Native 0.74部署至iPhone时出现“No bundle URL present”错误求助
解决React Native 0.74部署iPhone出现“No bundle URL present”错误的方案
- 确保设备与Mac处于同一WiFi网络(无线调试场景),或USB连接后设备已信任当前Mac。
- 重启Metro bundler并清除缓存,执行命令:
npx react-native start --reset-cache - 检查Xcode中项目的Bundle Identifier是否配置正确,同时确认当前iPhone已添加到开发者账号的设备列表中。
- 手动配置iOS项目中的bundle URL:
在iOS项目的AppDelegate.mm文件中,找到sourceURLForBridge方法,修改为指定Mac的IP地址(可通过ifconfig查询):
若使用Swift版本的NSURL *jsCodeLocation; #ifdef DEBUG jsCodeLocation = [NSURL URLWithString:@"http://192.168.x.x:8081/index.bundle?platform=ios&dev=true"]; #else jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endifAppDelegate.swift,则修改对应代码:let jsCodeLocation: URL #if DEBUG jsCodeLocation = URL(string: "http://192.168.x.x:8081/index.bundle?platform=ios&dev=true")! #else jsCodeLocation = Bundle.main.url(forResource: "main", withExtension: "jsbundle")! #endif - 摇晃iPhone调出调试菜单,选择「Configure Bundler」,输入Mac的IP地址和端口8081,完成后点击「Reload」重新加载应用。
- 清理Xcode缓存:按下
Cmd+Shift+K清理编译缓存,再按Cmd+Option+Shift+K清除build文件夹,之后重新编译部署。 - 暂时关闭Mac的防火墙,排除端口8081被拦截的可能。
内容的提问来源于stack exchange,提问作者Yashwanth Aras JV
相关产品推荐
相关产品推荐

