How to Change the Default iOS Simulator Device in React Native

How to Change the Default iOS Simulator Device in React Native

17 December 2024 Stephan Petzl Leave a comment Tech-Help

When developing with React Native, you might want to run your application on a different iOS simulator device than the default one. This guide will walk you through the steps required to specify a different simulator device when running your application.

Using the –simulator Flag

The most straightforward method to run your app on a specific simulator is by using the --simulator flag with the npx react-native run-ios command. This approach allows you to specify the desired simulator directly in the command line.

For example, to run your application on an iPhone 11, you would use:

npx react-native run-ios --simulator="iPhone 11"

Listing Available Simulators

To see a list of all available simulators, use the following command:

xcrun simctl list devices

This will display all the simulators installed on your machine, allowing you to choose the correct name for your desired device.

Adding a Script in package.json

Another convenient way to manage simulator preferences is by adding a script to your package.json file. Here’s how you can do it:


  "scripts": {
    "launch-ios": "react-native run-ios --simulator=\"iPhone SE (2nd generation)\""
  }
  

After adding this script, you can run your application on the specified simulator using:

npm run launch-ios

Practical Example

Suppose you are working on a React Native project and need to test your app on an iPad Pro. First, list available devices to find the correct simulator name:

xcrun simctl list devices

Then, execute the following command to run your app on an iPad Pro:

npx react-native run-ios --simulator="iPad Pro (12.9-inch) (5th generation)"

Conclusion

Choosing the right simulator can streamline your testing process and help you better emulate real-world conditions. These methods provide flexibility in selecting the simulator that best suits your needs.

Enhancing Testing with Repeato

For mobile app developers seeking a more efficient testing process, Repeato offers a robust solution. As a no-code test automation tool for iOS and Android, Repeato leverages computer vision and AI to create, run, and maintain automated tests quickly. This makes it an excellent option for React Native developers looking to improve their testing workflow without writing extensive test scripts. For more information about using Repeato, visit our React Native Testing page.

Like this article? there’s more where that came from!