React Native - Running IOS
React Native - Running on iOS
Section titled “React Native - Running on iOS”To run your React Native app on an iOS simulator or a physical iOS device, you must be using macOS. You’ll need Xcode and CocoaPods installed.
Prerequisites (macOS Only)
Section titled “Prerequisites (macOS Only)”- Xcode: Install the latest version from the Mac App Store. Xcode includes the iOS SDK, simulators, and build tools.
- Xcode Command Line Tools: Ensure they are installed. You can install them by opening Xcode, then Preferences > Locations, and selecting the latest version from the Command Line Tools dropdown. Alternatively, run
xcode-select --installin your terminal. - CocoaPods: A dependency manager for Swift and Objective-C Cocoa projects. If not already installed, run:
sudo gem install cocoapods.
Running on an iOS Simulator
Section titled “Running on an iOS Simulator”- Navigate to your React Native project’s root directory in the terminal.
- Ensure CocoaPods dependencies are installed for your project. If it’s a new project or you’ve added native modules, run:
cd ios && pod install && cd .. - Run the command to launch your app on the default simulator:
npx react-native run-iosOr, if you prefer using Yarn:
yarn react-native run-iosThis will build your app, install it on a simulator, and start the Metro bundler. The simulator will launch automatically if not already running.
To run on a specific simulator (e.g., “iPhone 14 Pro”): First, find the list of available simulators by running xcrun simctl list devices. Then use the --simulator flag:
npx react-native run-ios --simulator="iPhone 14 Pro"Running on a Physical iOS Device
Section titled “Running on a Physical iOS Device”- Connect your iOS device to your Mac via USB.
- Open your project’s
ios/{YourProjectName}.xcworkspacefile in Xcode. - In Xcode, select your device from the scheme chooser (next to the Play/Stop buttons).
- Configure code signing: Select your project in the Project navigator, then select your app target. Go to the ‘Signing & Capabilities’ tab and choose your Team. You may need an Apple Developer account (a free account allows deploying to your own devices).
- Press the Run button (▶) in Xcode, or from your terminal (with the device selected in Xcode or using
--device "Your Device Name"flag):
npx react-native run-ios --device "Your iPhone's Name"Note: You might need to trust the developer certificate on your iOS device (Settings > General > Device Management or VPN & Device Management).
Accessing the Developer Menu
Section titled “Accessing the Developer Menu”Once your app is running on the iOS simulator or device:
- On the iOS Simulator: Press
Cmd + D. - On a physical device: Shake the device.
You can also reload the app by pressing Cmd + R in the simulator (or R in the Metro bundler terminal). Fast Refresh is usually enabled by default, providing instant updates for most code changes.
For troubleshooting iOS build issues, opening the project in Xcode (ios/{YourProjectName}.xcworkspace) and checking build logs there can often provide more detailed error messages. Consult the official React Native documentation for more details.