React Native 开发报错 No bundle URL present

来源:互联网 发布:网络引擎优化 编辑:程序博客网 时间:2024/06/08 17:30

RN开发时候会遇到 模拟器正常调试;

但是真机调试的时候出现 :No bundle URL present

Make sure you’re running a packager server or have included a .jsbundle file in your application bundle

那么怎么解决呢?请往下看,大家经常用的代码 :

RN跳转的时候会用到:

jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@”index.ios” fallbackResource:nil];

但是这个方法是干哈的呢?有人是这样解释的:

React Native iOS在0.29.0版本中BundleURL加载方法做了重大改变,新增了RCTBundleURLProvider单例类专门处理BundleURL,使用NSUserDefaults保存配置信息。 
默认加载方式 
在Debug模式下,执行react-native-xcode.sh编译脚本会自动获取当前网卡en0的IP地址,并打入App包中一个配置文件ip.txt,App运行时会读取ip文件,自动生成Developer Server URL,通过这种加载方式,我们不再需要手动去把”localhost”改成Mac的IP了,每次编译都会读取当前最新的IP。

也就是说,真机调试的时候你这个地址其实是固定的,解决的方式就是增加一个判断:debug的时候,让地址变成你电脑的IP他就可以获取到地址,就可以真机调试了:

NSURL *jsCodeLocation;

[[RCTBundleURLProvider sharedSettings] setDefaults];

#if DEBUG

[[RCTBundleURLProvider sharedSettings] setJsLocation:@”192.168.17.22”];   //此处是你调试电脑的IP,不要乱写

#endif

jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@”index.ios” fallbackResource:nil];


0 0
原创粉丝点击