简体   繁体   English

如何在运行 React Native 应用程序的 iOS 设备中启用实时重载?

[英]How to enable Live Reload in iOS Device running React Native app?

I'm trying to enable Live Reload mode, but there is no such item in Dev Menu:我正在尝试启用实时重新加载模式,但开发菜单中没有这样的项目: 没有名为“实时重新加载”的项目

You have this problem is mainly because your device and your development machine is not in the same LAN.你出现这个问题主要是因为你的设备和你的开发机不在同一个局域网内。 check if it is.检查是否是。 Make sure your computer and your device connected in the save LAN, everything will be ok.确保您的计算机和您的设备连接在保存局域网中,一切都会好起来的。

After all ur devices connected to the same LAN.毕竟你的设备连接到同一个局域网。 And if u are using Xcode.如果您使用的是 Xcode。

  1. Close the React Native packager (or just close the terminal window)关闭 React Native 打包器(或者直接关闭终端窗口)
  2. Delete the app in your iOS device删除 iOS 设备中的应用程序
  3. Clean Xcode project.清理 Xcode 项目。
  4. Run command npm start -- reset-cache运行命令npm start -- reset-cache

Then everything will be OK.那么一切都会好起来的。

You need to edit the source for jsCodeLocation from your AppDelegate.您需要从 AppDelegate 编辑jsCodeLocation的源代码。

The main problem that the主要问题是

jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];

is looking for localhost by default, in simulator it will work as simulator and pc are on the same machine, but for device localhost will be different so to make it work, you need to change that line to默认情况下正在寻找localhost ,在模拟器中它将作为模拟器和电脑在同一台机器上工作,但对于设备localhost将不同,因此要使其工作,您需要将该行更改为

jsCodeLocation = [NSURL URLWithString:@"http://192.168.1.16:8081/index.ios.bundle?platform=ios&dev=true&minify=false&hot=true"];

here 192.168.1.16 change it to your PC local IP address这里192.168.1.16将其更改为您的 PC 本地 IP 地址

If u are using IOS Simulator, follow the menu Hardware > Shake Gesture , and click the Enable Live Reload option.如果您使用的是 IOS 模拟器,请按照菜单Hardware > Shake Gesture ,然后单击Enable Live Reload选项。

Hope it helps!希望有帮助! :) :)

If you are running the simulator, make sure you sure you "Connect Hardware Keyboard"如果您正在运行模拟器,请确保您“连接硬件键盘”

在此处输入图片说明

In my case, I had a local ethernet connection that was taking priority on en0, so I had to change the script at:就我而言,我有一个优先于 en0 的本地以太网连接,因此我不得不在以下位置更改脚本:

node_modules/react-native/react-native-xcode.sh

from来自

IP=$(ipconfig getifaddr en0)

to

IP=$(ipconfig getifaddr en1)

since my wifi was on that port.因为我的wifi在那个端口上。 Verify that with terminal: networksetup -listallhardwareports使用终端验证: networksetup -listallhardwareports


All this I learned from the following blog post:所有这些都是我从以下博客文章中学到的:

https://www.stevetrefethen.com/blog/react-native-bundle-loading-failing-on-a-physical-device https://www.stevetrefethen.com/blog/react-native-bundle-loading-failing-on-a-physical-device

Thanks Steve Trefethen!谢谢史蒂夫·特雷费森!


I'm not sure what the permanent solution should be, but it seems the script should be checking for wifi only connections somehow.我不确定永久解决方案应该是什么,但似乎脚本应该以某种方式检查仅 wifi 连接。

If you are running the app on your actual native device.如果您在实际的本机设备上运行该应用程序。 Then shake the device and it will pop up the me menu.然后摇动设备,它会弹出我的菜单。

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

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