我尝试将AwesomeProject应用程序构建到设备上.构建成功并且启动画面显示,但随后我看到一个红色的"无法连接到开发服务器"屏幕.它说"确保节点服务器正在运行 - 从React root运行'npm start'."
看起来节点服务器已经在运行,因为当我这样做时,npm start我收到一条EADDRINUSE消息,说端口已经在使用中.
小智 10
从设备访问开发服务器您可以使用开发服务器在设备上快速迭代.要做到这一点,您的笔记本电脑和手机必须在同一个wifi网络上.
ps:http://facebook.github.io/react-native/docs/runningondevice.html#content
另一个潜在的问题(这发生在我身上):即使您进行了所有必要的代码更改(参见http://moduscreate.com/automated-ip-configuration-for-react-native-development/以获得良好的演练) ,启动服务器等,它可能仍然因App Transport Security而失败.您需要将您的IP地址添加到NSExceptionDomains应用程序Info.plist文件的列表中,或者完全禁用ATS(不鼓励 - 阅读上面的文章以了解原因).
示例条目:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>YOUR-IP-HERE</key>
<dict>
<key>NSTemporaryExceptionAllowsInsecureHTTPSLoads</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>1.0</string>
<key>NSTemporaryExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
在AppDelegate.m:
To run on device, change localhost to the IP address of your computer, and make sure your computer and iOS device are on the same Wi-Fi network.
我在react-native github issues上发现了一个相关的问题。
在没有服务器的情况下运行应用程序的说明:https://github.com/facebook/react-native/issues/240
| 归档时间: |
|
| 查看次数: |
11972 次 |
| 最近记录: |