facebook / metro

🚇 The JavaScript bundler for React Native
https://metrobundler.dev
MIT License
5.24k stars 626 forks source link

Debug react native ios app offline mode. #1307

Closed gioorange closed 3 months ago

gioorange commented 4 months ago

Hi,

I'm developing an app that allow to connect wifi of a device, wifi that can't reach internet. With android I had no problem testing app, even if the app was connected to this wifi, so even if the smartphone is offline.

With iOS I can't obtain the sam result, when the app connect to wifi, I have the error "Lost connection to metro" and so I can't debug anymore.

I'm using metro 0.80.4.

Can you suggest me a way to bypass this?

Thanks in advance.

huntie commented 4 months ago

This is a limitation with using the iOS simulator — it's all or nothing in terms of reaching the internet and your local network. Your React Native app needs to communicate with the dev server (http://localhost:8081) in order to debug.

➡️ In the past, I've worked around this by mocking network availability using an app-specific NetInfo wrapper.

A suggestion to use an extra Xcode tool here (I haven't tried): https://github.com/react-native-netinfo/react-native-netinfo/issues/403

Note that there is also a bug around network state in iOS Simulator. The suggested workaround is to use a physical device.

gioorange commented 4 months ago

In my situation, in reality, I resolved not using metro but seeing the logs from xcode.

Infact, even if the app say "Lost connection to metro", the app still run.