我有一个非常简单的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;
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
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[self.view addSubview:delegate.rootView];
我对如何解决这个问题感到困惑。我已经尝试了以下所有方法:
- npm start
- npm start --reset-cache
- 删除node_modules目录并重新安装
- 卸载并重新安装node、watchman、react-native和npm
- 在物理设备和模拟器上尝试
我同时遇到了其他问题。这里是我提出的另一个问题,其中可能包含一些信息:React Native: Unable to Resolve Module
http://localhost:8081/debugger-ui
。 - Andrew Lireact-native init
生成的代码,则应该解决连接问题。 - NiFi