简体   繁体   English

React-Native:如何在真正的 iOS 设备上使用“远程 JS 调试器”?

[英]React-Native: how to use “Remote JS Debugger” on real iOS-device?

I'm wondering if react-native's Remote Debugger mode would be possible also on real device.我想知道在真实设备上是否也可以使用 react-native 的远程调试器模式。 But it stops me with an error page stating但它通过一个错误页面说明阻止了我

"Connecting to http://localhost:8081/debugger-proxy?role=client timed out" “连接到http://localhost:8081/debugger-proxy?role=client超时”

The interesting fact here is that this URL won't also work on my developer machine.这里有趣的事实是这个 URL 在我的开发者机器上也不起作用。

Opening this URL ( http://localhost:8081/debugger-proxy?role=client ) in a browser on my developer machine with running packager.js will respond with:在运行 packager.js 的开发人员机器上的浏览器中打开此 URL ( http://localhost:8081/debugger-proxy?role=client ) 将响应:

Cannot GET /debugger-proxy?role=client无法 GET /debugger-proxy?role=client

When I turn off Remote debugger, everything works as expected.当我关闭远程调试器时,一切都按预期工作。

Steps to reproduce:重现步骤:

  1. react-native init testapp react-native init testapp
  2. cd testapp/ios cd testapp/ios
  3. open the .xcodeproj-File with XCode使用 XCode 打开 .xcodeproj-File
  4. Select my connected iPhone as target device选择我连接的 iPhone 作为目标设备
  5. Run the application运行应用程序

The application will fetch the source code from my local machine.该应用程序将从我的本地机器获取源代码。 In order to make this work, both, the iPhone-device and my iMac, are connected to the same WiFi.为了完成这项工作,iPhone 设备和我的 iMac 都连接到同一个 WiFi。

在此处输入图片说明

The ReactNative-Application is executed on the iPhone as expected. ReactNative-Application 按预期在 iPhone 上执行。 With the shake-gesture I spawn the developer menu and select the option "Debug JS Remotely".通过摇动手势,我会生成开发人员菜单并选择“远程调试 JS”选项。

在此处输入图片说明

Now this error appears as mentioned above.现在这个错误出现如上所述。

Following a side note in running-on-real device I changed the Host from localhost to the IP-Address of my Mac in RCTWebSocketExecutor.m, but this results in an endlos loop while fetching.根据在真实设备上运行的旁注,我在 RCTWebSocketExecutor.m 中将主机从本地主机更改为我的 Mac 的 IP 地址,但这会导致在获取时出现 endlos 循环。

The Question is:问题是:

How can I use the Remote JS Debugging -Feature on real device?如何在真实设备上使用远程 JS 调试功能?

在此处输入图片说明

Update更新

After further investigation I came to the conclusion that this might be a bug and opened the following issue on GitHub.经过进一步调查,我得出结论,这可能是一个错误,并在 GitHub 上打开了以下问题

In chrome browser, I have changed在chrome浏览器中,我已经改变了

localhost:19001/debugger-ui本地主机:19001/debugger-ui

to

192.168.0.4:19001/debugger-ui 192.168.0.4:19001/调试器-ui

and it worked.它奏效了。 Replace 192.168.0.4 with your ip address.将 192.168.0.4 替换为您的 IP 地址。

On iOS devices, open the file RCTWebSocketExecutor.m from react-native/Libraries/WebSocket/RCTWebSocketExecutor.m and change "localhost" to the IP address of your computer, (don't forget the correct port. eg: 192.168.1.6::8880) then select "Debug JS Remotely" from the Developer Menu.在 iOS 设备上,从react-native/Libraries/WebSocket/RCTWebSocketExecutor.m打开文件 RCTWebSocketExecutor.m 并将“localhost”更改为您计算机的 IP 地址, (don't forget the correct port. eg: 192.168.1.6::8880)然后从开发者菜单中选择“Debug JS Remotely”。

NOTE: remove the app from your device, close the terminal that opened for creating bundle.js.注意:从您的设备中删除该应用程序,关闭为创建 bundle.js 而打开的终端。 finally press the Play button from your Xcode.最后按下 Xcode 中的 Play 按钮。

here is the official guide from react-native website:这是来自 react-native 网站的官方指南

We had a similar issue here in 2020 and now there is a better solution which is to update the IP of the target machine directly from the app.我们在 2020 年遇到了类似的问题,现在有一个更好的解决方案,即直接从应用程序更新目标机器的 IP。 Be on the same wifi with both the computer and the device - even if they are connected with a USB.与计算机和设备在同一个 wifi 上 - 即使它们通过 USB 连接。

  1. Shake the phone to get the menu摇晃手机获取菜单
  2. Select Configure Bundler选择配置捆绑程序
  3. Insert the IP of the computer插入电脑IP
  4. Press Apply Changes应用更改

Now you should get debug data on the computer.现在您应该在计算机上获得调试数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM