如何通过Xcode为设备构建React Native iOS应用程序?

Mar*_*tez 10 react-native

我尝试将AwesomeProject应用程序构建到设备上.构建成功并且启动画面显示,但随后我看到一个红色的"无法连接到开发服务器"屏幕.它说"确保节点服务器正在运行 - 从React root运行'npm start'."

看起来节点服务器已经在运行,因为当我这样做时,npm start我收到一条EADDRINUSE消息,说端口已经在使用中.

小智 10

从设备访问开发服务器您可以使用开发服务器在设备上快速迭代.要做到这一点,您的笔记本电脑和手机必须在同一个wifi网络上.

  1. 打开iOS/AppDelegate.m
  2. 将URL中的IP从localhost更改为笔记本电脑的IP
  3. 在Xcode中选择您的手机作为构建目标,然后按"构建并运行"

ps:http://facebook.github.io/react-native/docs/runningondevice.html#content


Lan*_*tig 5

另一个潜在的问题(这发生在我身上):即使您进行了所有必要的代码更改(参见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)


Mar*_*tez 1

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