react native 真机调试appdelegate.m找不到ip地址的处理
2016-10-11 16:57
429 查看
现象
对着书本及网上文章,如果要进行真机调试,得修改appdelegate.m里的ip,但高版本的react native已经做了大变动。 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。
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@”index.ios” fallbackResource:nil];
解决方法
手动设置IP RCTBundleURLProvider在接口中暴露了jsLocation属性,可以通过setJsLocation手动设置IP。
NSURL *jsCodeLocation;
[[RCTBundleURLProvider sharedSettings] setDefaults];
if DEBUG
[[RCTBundleURLProvider sharedSettings] setJsLocation:@”192.168.3.13”];endif
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@”index.ios” fallbackResource:nil];另需要在Info设置NSAppTransportSecurity的NSAllowsArbitraryLoads为true即可。
总之
RCTBundleURLProvider类做了一些消息和属性的封装,可以通过判断是否DEBUG环境然后做不同的设置。
相关文章推荐
- [转]react native 真机调试appdelegate.m找不到ip地址的处理
- ReactNative真机调试
- React native真机调试
- React Native使用Expo真机调试检测不到state解决方法
- react-native真机调试报错
- React-Native:解决真机调试时候Could not get BatchedBridge, make sure your bundle is packaged properly
- React Native真机调试
- React-Native真机调试(Android,Windows)
- react-native IOS真机调试技巧
- iOS调试——打全局断点后总是在断在App delegate里处理办法
- React Native:真机断点调试+跨域资源加载出错问题解决
- React-Native真机调试(Android,Windows)
- React-Native调试状态下App运行缓慢问题解决方案
- React-Native 'RCTRootView.h' file not found AppDelegate.m
- react -native Android真机调试注意的问题
- 如何愉快地调试一个 React Native for Android APP
- React Native 真机调试
- React-Native初学者的模拟器调试及真机调试
- react-native+vm+macos X+ios 真机调试
- react native mac 下真机调试 Could not connect to development server.