0
0
React-nativeHow-ToBeginner ยท 4 min read

How to Build React Native Apps for iOS: Step-by-Step Guide

To build a React Native app for iOS, use the npx react-native run-ios command which compiles and launches the app in the iOS simulator. For a production build, open the ios/YourApp.xcworkspace in Xcode, then build and archive the app for deployment on a real device or App Store.
๐Ÿ“

Syntax

The main command to build and run a React Native app on iOS simulator is npx react-native run-ios. This command compiles your JavaScript and native code, then launches the app in the iOS simulator.

For production builds, open the ios/YourApp.xcworkspace file in Xcode. From there, you can select a device or simulator, build the app, and archive it for release.

bash
npx react-native run-ios

# To open the iOS project in Xcode
open ios/YourApp.xcworkspace
๐Ÿ’ป

Example

This example shows how to run your React Native app on the iOS simulator using the CLI.

bash
npx react-native init MyApp
cd MyApp
npx react-native run-ios
Output
info Found Xcode workspace "MyApp.xcworkspace" info Found booted simulator "iPhone 14" info Run CLI with Xcode build info Launching "com.myapp" on iPhone 14 simulator info Successfully launched the app on the simulator
โš ๏ธ

Common Pitfalls

  • Xcode not installed or outdated: You must have Xcode installed and updated to the latest version to build for iOS.
  • Missing CocoaPods dependencies: Run cd ios && pod install before building to install native dependencies.
  • Simulator not booted: The CLI tries to boot a simulator automatically, but sometimes you need to open it manually via Xcode or Simulator app.
  • Build errors in Xcode: Open the project in Xcode to see detailed errors and fix signing or configuration issues.
bash
Wrong:
npx react-native run-ios

Right:
cd ios
pod install
cd ..
npx react-native run-ios
๐Ÿ“Š

Quick Reference

StepCommand/ActionPurpose
1npx react-native init MyAppCreate a new React Native project
2cd ios && pod installInstall iOS native dependencies
3npx react-native run-iosBuild and run app on iOS simulator
4open ios/YourApp.xcworkspaceOpen project in Xcode for advanced build and deployment
โœ…

Key Takeaways

Use npx react-native run-ios to quickly build and launch your app on the iOS simulator.
Always run pod install inside the ios folder to install native dependencies before building.
Open the Xcode workspace for production builds, device deployment, and detailed error debugging.
Keep Xcode updated and ensure your Mac meets React Native iOS build requirements.
Manually boot the iOS simulator if the CLI does not launch it automatically.