【发布时间】:2018-04-12 04:29:22
【问题描述】:
在包含 React 库及其依赖项的 iOS 应用程序中,我在启动时有以下代码:
NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.bundle?platform=ios"];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"App"
initialProperties:@{}
launchOptions:@{}];
rootView.frame = self.view.bounds;
[self.view addSubview:rootView];
当我在模拟器中运行它时,即使在禁用 ATS 并运行 npm start 之后,我也会得到:
Failed to load bundle(http://localhost:8081/index.bundle?platform=ios) with error:(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
- WiFi is enabled and connected to the same network as the Node Server
我的package.json 文件是这样的:
{
"name": "AwesomeProject",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-native-scripts": "1.11.1",
"jest-expo": "25.0.0",
"react-test-renderer": "16.2.0"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"expo": "^25.0.0",
"react": "16.2.0",
"react-native": "0.52.0",
"react-navigation": "^1.5.11"
}
}
另一件事...似乎npm start 导致打开端口 19000,而不是 8081,但是当我转到 http://localhost:19000 并使用他们在该 JSON 中提供的捆绑 URL 时,它告诉我我需要使用世博会。但是https://facebook.github.io/react-native/docs/integration-with-existing-apps.html 中没有提到这些,我不确定从这里去哪里。有什么想法吗?
【问题讨论】:
-
你能发布你的
package.json吗? -
@Stackia 发布
标签: ios react-native