实际开发中需要进行真机debug调试, 但是团队开发设置的电脑IP需要灵活,不能写死,所以现在以向Xcode注入脚本的方式,动态获取电脑IP来进行.
添加运行脚本
- 使用
ifconfig
命令来获取ip
1 | ifconfig | grep inet\ | tail -1 | cut -d " " -f 2 |
- 将命令写成脚本,进行添加
1 | INFOPLIST="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" |
编辑AppDelegate.m
- 在iOS的AppDelegate.m中替换为预处理器指令.
1 | NSURL *jsCodeLocation; |
参考文献:
https://github.com/facebook/react-native/issues/4245
http://moduscreate.com/automated-ip-configuration-for-react-native-development/