【发布时间】:2017-10-11 00:17:21
【问题描述】:
我有一个非常简单的 React Native 项目,我正在尝试开始工作。这是一个简单地将 RCTRootView 添加到 UIViewController 的 iOS 项目。当我从 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 in 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];
ViewController.m in viewDidAppear:
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[self.view addSubview:delegate.rootView];
我不知道如何解决这个问题。我已经尝试了以下所有方法:
- npm 开始
- npm start --reset-cache
- 删除 node_modules 目录并重新安装
- 卸载并重新安装 node、watchman、react-native 和 npm
- 在物理设备和模拟器上试用
有没有人发现我的代码有任何问题或知道问题可能是什么?我愿意通过电子邮件或电话交谈来解决这个问题。我越来越绝望了。
我同时遇到了问题。这是我问的另一个问题,其中可能包含一些信息:React Native: Unable to Resolve Module
【问题讨论】:
-
您是否在浏览器中打开了开发服务器选项卡?类似于
http://localhost:8081/debugger-ui -
不,我没有打开那个。我从来没有读过这...你将不得不指出我正确的方向。不知道如何使用该工具。
-
我无法让震动器工作并显示开发者菜单。我在物理设备上运行调试。我还需要做什么才能让它显示出来?
-
太棒了,很高兴能帮上忙!
标签: ios objective-c node.js reactjs react-native