Running React native in your iphone throw network ,is it possible?

hipster' Santos
5 min readJul 12, 2024

--

yes the answer is yes, I've been struggling to run core react native application not expo , instead react native app , since I was using xcode 13 I had some limitation:

first I was able only to install react-native under o equal to 0.73.2 react native version , 'casue I'm xcode 13. so I couldn't hook my iphone and debug throght xcode , here's where my mind started to be unquite , 'cause I need to run it on my iphone , this time a had presentation set next day , so after some hours of research I've splitted the research and started assembly all peaces till I found this solution I'll show below .

In my mind is there any way to run react native app in my iphone 14 pro through network?

Yes, you can run a React Native app on your iPhone 14 Pro like I'm doing over the current network using Wi-Fi, which it'll allows you to deploy and debug the app without needing to use a physical cable connection(no hook up needs ). Here’s how you can set it up:

Quick Heads-up: Make sure your iPhone 14 Pro and your development machine (Mac) are on the same Wi-Fi network.

Ensure that you have Xcode installed and set up properly.

1. Update Your Podfile for Network Debugging

Make sure your Podfile is configured correctly. Add the react-native path if it’s missing: here it goes an example of how your podfile would looks like:

platform :ios, '13.0'  # or the minimum version required by your app

target 'YourApp' do
config = use_native_modules!

use_react_native!(
:path => config[:reactNativePath],
:app_path => "#{Pod::Config.instance.installation_root}/.."
)

target 'YourAppTests' do
inherit! :complete
# Pods for testing
end

post_install do |installer|
react_native_post_install(
installer,
config[:reactNativePath],
:mac_catalyst_enabled => false,
)
end
end

2. Install CocoaPods Dependencies

If you have made changes to the Podfile, install or update the CocoaPods dependencies:

cd ios
pod install
cd ..

3. Configure Network Debugging

To run the app over the network, you need to enable network debugging in Xcode:

  1. Open your Xcode project: open ios/YourApp.xcodeproj
  2. Select Your Target: In the Xcode project navigator, select the target for your app.
  3. Go to the Scheme Editor:
  • Click on the Scheme dropdown (next to the “Run” button at the top of Xcode).
  • Choose “Edit Scheme…”
  1. Update the Run Settings:
  • Go to the “Run” section in the left sidebar.
  • In the “Info” tab, set the “Build Configuration” to Debug.
  1. Enable Debugging Over Network:
  • Go to the “Arguments” tab.
  • Add the following argument under “Arguments Passed On Launch”
-r

Ensure Metro Bundler is Listening on All Interfaces

If you have issues connecting to the development server, make sure Metro Bundler is set to listen on all network interfaces. Start Metro Bundler with:

npx react-native start --host 0.0.0.0

Connect Your iPhone to the Metro Bundler

Open the React Native Debug Menu on your iPhone:

  • Shake the device or press Cmd + D in the simulator to open the developer menu.
  • Select “Dev Settings” > “Debug server host & port for device”.
  • Enter the IP address of your development machine followed by the port number, e.g., 192.168.1.2:8081

Restart Your App

  • Reload the app by shaking the device and selecting “Reload” or by pressing Cmd + R in the simulator.

Yes, you can run a React Native app on your iPhone 14 Pro over the network using Wi-Fi, which allows you to deploy and debug the app without needing to use a physical cable connection. Here’s how you can set it up:

Prerequisites

  1. Make sure your iPhone 14 Pro and your development machine (Mac) are on the same Wi-Fi network.
  2. Ensure that you have Xcode installed and set up properly.

Steps to Run React Native App on iPhone 14 Pro Over Network

1. Update Your Podfile for Network Debugging

Make sure your Podfile is configured correctly. Add the react-native path if it’s missing:

ruby
Copy code
platform :ios, '13.0'  # or the minimum version required by your app
target 'YourApp' do
config = use_native_modules!
use_react_native!(
:path => config[:reactNativePath],
:app_path => "#{Pod::Config.instance.installation_root}/.."
)
target 'YourAppTests' do
inherit! :complete
# Pods for testing
end
post_install do |installer|
react_native_post_install(
installer,
config[:reactNativePath],
:mac_catalyst_enabled => false,
)
end
end

2. Install CocoaPods Dependencies

If you have made changes to the Podfile, install or update the CocoaPods dependencies:

sh
Copy code
cd ios
pod install
cd ..

3. Configure Network Debugging

To run the app over the network, you need to enable network debugging in Xcode:

  1. Open your Xcode project: open ios/YourApp.xcodeproj
  2. Select Your Target: In the Xcode project navigator, select the target for your app.
  3. Go to the Scheme Editor:
  • Click on the Scheme dropdown (next to the “Run” button at the top of Xcode).
  • Choose “Edit Scheme…”
  1. Update the Run Settings:
  • Go to the “Run” section in the left sidebar.
  • In the “Info” tab, set the “Build Configuration” to Debug.
  1. Enable Debugging Over Network:
  • Go to the “Arguments” tab.
  • Add the following argument under “Arguments Passed On Launch”:
  • diff
  • Copy code
  • -r
  1. Select Your Device:
  • In the Xcode toolbar, click the device dropdown.
  • Select your iPhone 14 Pro from the list of devices.
  1. Run the Project:
  • Click the “Run” button or press Cmd + R to build and run the app on your iPhone 14 Pro.

4. Run the React Native App

Once the app is running on your iPhone, you can start the Metro bundler using:

sh
Copy code
npx react-native start

The React Native CLI will start the development server, and you can access it via the network.

5. Ensure Metro Bundler is Listening on All Interfaces

If you have issues connecting to the development server, make sure Metro Bundler is set to listen on all network interfaces. Start Metro Bundler with:

sh
Copy code
npx react-native start --host 0.0.0.0

This will make Metro Bundler available on all network interfaces.

6. Connect Your iPhone to the Metro Bundler

Open the React Native Debug Menu on your iPhone:

  • Shake the device or press Cmd + D in the simulator to open the developer menu.
  • Select “Dev Settings” > “Debug server host & port for device”.
  • Enter the IP address of your development machine followed by the port number, e.g., 192.168.1.2:8081.

7. Restart Your App

  • Reload the app by shaking the device and selecting “Reload” or by pressing Cmd + R in the simulator.

Troubleshooting Network Issues

If you run into issues, consider the following:

  • Check Firewall Settings: Ensure that your Mac’s firewall allows incoming connections for the React Native development server.
  • Verify IP Address: Make sure you’re using the correct IP address of your development machine.
  • Network Configuration: Ensure that no VPNs or network configurations are blocking access.

Summing up

By following these steps, you can run and debug your React Native app on your iPhone 14 Pro over a network connection. Here’s a summary of the commands and steps:

# Install CocoaPods dependencies
cd ios
pod install
cd ..

# Start the Metro Bundler
npx react-native start --host 0.0.0.0

http://<your-local-ip>:8081

ifconfig

Replace <your-local-ip> with the local IP address of your Mac. You can find it using:


http://192.168.1.2:8081

--

--

hipster' Santos
hipster' Santos

Written by hipster' Santos

Fullstack developer , Distributed system engineer,Competitive programmer find at https://github.com/HipsterSantos

No responses yet