React Native:无法连接到开发服务器
我有一个非常简单的React Native项目,我正在努力工作。 这是一个iOS项目,简单地将RCTRootView添加到UIViewController。 当我从Xcode运行应用程序时,出现错误的红色屏幕:
Could not connect to development server. Ensure the following: - Node server is running and available on the same network - run 'npm start' from react-native root - Node server URL is correctly set in AppDelegate
AppDelegate.h
@property (strong, nonatomic) RCTRootView *rootView;
application: didFinishLaunchingWithOptions:
AppDelegate.m application: didFinishLaunchingWithOptions:
NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios"]; self.rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"HelloReact" initialProperties:nil launchOptions:launchOptions];
viewDidAppear:
ViewController.m viewDidAppear:
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; [self.view addSubview:delegate.rootView];
我对如何解决这个问题感到茫然。 我已经尝试了以下所有内容:
- npm开始
- npm start –reset-cache
- 删除了node_modules目录并重新安装
- 卸载并重新安装节点,看守,react-native和npm
- 尝试在物理设备和模拟器
有没有人看到我的代码中有任何错误或知道这个问题可能是什么? 我愿意通过电子邮件或电话来解决这个问题。 我越来越绝望了
我有同时发生的问题。 以下是我询问的可能包含一些信息的其他问题: React Native:无法parsing模块
在iOS设备上运行React Native应用程序需要指定主机的IP地址而不是localhost
:
jsCodeLocation = [NSURL URLWithString:@"http://DEV_SERVER_URI:8081/index.ios.bundle?platform=ios&dev=true"];
更具体的说明可以在这个答案中find。