How to I connect my iPhone via USB tethering to an Expo server on my Mac - without using WiFi or cellular?

I'm running Expo on my Mac for developing apps.

I want to connect my iPhone, which runs my own app I'm developing, to the Expo server using USB tethering only - as I haven't got a SIM card and WiFi is not an option either.

How can I accomplish this?

Update:

I can turn on internet sharing for "iPhone USB" but it doesn't appear under "Preferences -> Network" Here's the ifconfig output when I connect my iPhone in this entry gets added:

en33: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=400<CHANNEL_IO>
    ether a2:99:9b:92:ba:7c 
    inet6 fe80::80b:d418:2177:9032%en33 prefixlen 64 secured scopeid 0x9 
    inet 169.254.246.125 netmask 0xffff0000 broadcast 169.254.255.255
    nd6 options=201<PERFORMNUD,DAD>
    media: autoselect (100baseTX <full-duplex>)
    status: active

In Sharing "Share your connection" I set it to Ethernet and wifi both gave the same ip.


Solution 1:

This is really quite simple - just plug the phone via a Lightning to USB cable into the Mac to get a network connection.

The network connection will be between the iPhone and the Mac only. It is not by default an internet connection for the phone, but that is not needed for Expo development.

On the Mac in System Preferences > Network, you'll see the phone listed as "iPhone USB". Click on "iPhone USB" and you'll see the phone's IP-address.

If you have other means of connection enabled on the phone, you might need to remove the checkmark from "Disable unless needed" and click Apply - but apart from that, you automatically have a network connection to the Mac now.

If you're running a macOS version where you do not see it in the graphical interface, you can instead run this Terminal command:

ifconfig

Compare the output before and after plugging in the iPhone, and you'll see that a new network interface named "enXX" (where X's are numbers) appears after plugging in the iPhone. The IP address listed is the IP address of your computer in this private network.

Now to make sure that the Expo server uses this private network instead of your WiFi for communicating with the phone, you set its initial interface like this in the Terminal:

export EXPO_DEVTOOLS_LISTEN_ADDRESS=169.254.246.125
export REACT_NATIVE_PACKAGER_HOSTNAME=169.254.246.125
expo start

Replace 169.254.246.125 with the actual IP address you see listed for your computer.

If you also want to share the internet connection of your Mac with the phone, you can do that from System Preferences > Sharing > Internet Sharing. This enables NAT, so you will experience that the interface on your Mac, as well as the interface on your iPhone, now have different IP addresses, and you'll need to update the commands above accordingly.

Solution 2:

I'm a little unsure if this is what you're looking for, but...

To get internet on an iPhone without Wi-Fi or Cellular data, you can buy a USB to Ethernet adapter that works with iPhone and connect to a standard ethernet cable:

Lightning to Ethernet (directly): https://www.belkin.com/us/adapters/ethernet/ethernet-power-adapter-with-lightning-connector/p/p-f8j227/

Lightning to USB to Ethernet (Apple made adapters, cheaper, 100Mb/s):

  • https://www.apple.com/shop/product/MK0W2AM/A/lightning-to-usb-3-camera-adapter
  • https://www.apple.com/shop/product/MC704LL/A/apple-usb-ethernet-adapter

Amazon Basics gigabit adapter is reasonably priced and works very well.

  • https://www.amazon.com/AmazonBasics-1000-Gigabit-Ethernet-Adapter/dp/B00M77HMU0

Solution 3:

You basically want some apps you are developing to connect to a web server locally on your PC.

All you need to to do is to create a Wireless Local Area Network (LAN) beween your PC and iPhone using a WiFi router. That's it. Once both the PC and the iPhone are connected by Wifi to the router, your iPhone apps should be easily able to communicate with the web server on your PC using the PC's local IP address.

If you don't want to use a router, and connect your iPhone directly to your Mac, just activate Wifi Hotspot on your Mac using "Internet Sharing", and connect your iPhone directly to it through wifi. To do this on your mac, go to System Preferences > Sharing > Internet Sharing (More details here - share the Internet connection on Mac with other network users).