Create React Native App Change iOS Device - react-native

I am trying to launch a react native app, created with create-react-native-app, however I do not want it to launch in the iPhone 6.
How can I change the device? All docs I can find give advice on apps created with react-native init.
npm run ios -- --simulator="iPhone X" does not seem to work

You can specify a device by using
react-native run-ios --simulator="iPhone 5s"
Just enter the device ID you want and all should be merry. Worth noting there is no way to currently set/change the default.

Related

Are there any ways to set particularly iPhone 6s when debugging in React Native using VSCode?

I'm trying to debug my app, and the React Native Tools extension automatically opens my app in iPhone X, because of weakness of my mac mini, I've been looking for a way to change the device but there's nothing. How can I change it?
I use command line to specify the simulator.
react-native run-ios --simulator="iPhone 6s"

React Native Expo app - unable to open app in iOS emulator

I want to run my React Native app in the iOS emulator. Here is what I done so far:
I installed XCode, along with its command line tools, and can bring up the emulator without issue.
I created an empty React Native app using the Expo CLI, per the instructions here. https://facebook.github.io/react-native/docs/getting-started. I am running on Node v10.0.0 on a Mac.
Afterwards I install all the necessary dependencies.
I then run "sudo npm run ios". This fires up the Metro Bundler as well as the iOS simulator. The Simulator loads up after about 5 minutes of waiting, but my app does not start up.
What am I missing here?
I should note that I prefer to stick with Expo, so I'd prefer not to have to eject.

How to properly start a detached React Native app

I am using React Native for the first time and I can see that we can detach from the Expo. I have no reason to detach, but I am sure will have later so I will detach from the start.
Question: What is the commands to start directly detached app using react native commands.
I have used create-react-native-app my-app then run expo detach this seemed to detach the app but for some reason only android folder is showing while ios folder is missing, anyone have any idea how do I have both platforms created on a detached version!
Thanks
A Mac is required to build projects with native code for iOS. You can follow the Quick Start to learn how to build your app using Create React Native App instead.
As per the react-native docs, you can't detach & develop for iOS unless you are on a Mac. Link(Under Building Projects with Native Code)

Can I use any other app instead of Expo to run react native app?

Can I use any other app instead of Expo to run react native app?
Expo is not compatible with my phone.
Yes, you can use the way suggested in the react-native docs under using a real device. You'll need adb installed, then just enable USB debugging on your phone and plug it in. Run react-native run-android in the command line to send your program to your phone.
Note that these steps may differ depending on how far you've followed to the directions for either expo or react-native.

Running multiple iOS simulators with React Native?

I want to run the app in multiple IOS simulators with React Native so will be able to compare the iPhone version vs the iPad version
I see there is some one already did it
https://ashleyd.ws/running-multiple-ios-simulators-with-react-native/
but unfortunate he did not mention how he did it
Using MacOs Terminal, launch first simulator:
cd /Applications/Xcode.app/Contents/Developer/Applications
open -n Simulator.app
cd <your react native project>
react-native run-ios
Now, launch 2nd simulator:
cd /Applications/Xcode.app/Contents/Developer/Applications
open -n Simulator.app
Click "Ok" when you get "Unable to boot device in current state"
Change simulator to be different than first simulator (e.g. Hardware -> Device -> iPhone 6s)
cd <react-native project>
react-native run-ios --simulator "iPhone 6s" (or whatever simulator you chose in step 8).
Note: In the last step, you can disregard the terminal output since it indicates that it is launching using the 1st simulator hardware. In fact, it is launching into the 2nd simulator (as desired).
I got two separate react native apps running at the same time doing this
I entered the following in one terminal for the first app
react-native run-ios --simulator="iPhone X"
After that finished building I opened another terminal and ran for the second app
react-native run-ios --simulator="iPhone XS" --port=8088
Then that built the second app on the new simulator and using a different port for the metro bundler. However after the second one built the first app changed its screen from the first app to the second app. I hit the home button and just re-opened the first app. One observation is that the first app seems to have both apps installed in the simulator while the second one does not.
This isn't the direct answer to your question, but I think it gives a better solution than running different simulators.
You can check the following lib called ScreenSwitcher.
It basically use the same simulator, in our case iPhone 6 plus only and you can check and inspect any other smaller screen on it directly.
I find that approach more efficient and faster.
Opening multiple simulators from the command-line did not work for me. With some manual interaction I got this to work with simulator 10.0 and react-native 0.47.2 - its based on the fact that react native always opens the app in the last opened simulator:
manually open simulator
start app: react-native run-ios
manually do: Hardware -> Device -> select iOS -> select Device (different then before !)
that will open a second simulator
start app again: react-native run-ios
this opens the app in the second simulator
I have Used more than 2 Simulator at a one time by using different terminals and they works well
react-native run-ios --simulator="iPhone 11 Pro Max" //write like this.
react-native run-ios --simulator="iPhone 6". //write like this.
react-native run-ios --simulator="iPhone 12 Pro Max" //write like this.
react-native run-ios --simulator="iPhone 8 Plus".
Another option is to run the app from xcode plus open another one from react-native commandline. Each normally opens their own simulator (I wonder why). And if I run an end-to-end test with Detox then it also opens its own simulator.
Some of the answers above helped me, but I think they are incomplete.
I have been using this technique to test a two player game (halfchess.com) on iOS simulators. My goal is to run two instances of halfchess at the same time.
To have my app running on two simulators, I first need to install Expo app on multiple simulators. Below steps are for the first time only.
react-native-scripts start to run the package manager. Copy the
expo URL for the app, for ex., exp://172.20.10.2:19000 to clipboard.
Run ios simulator from within above (press i). This opens a default simulator and runs the app. Lets call the default device X.
Goto menu Hardware -> Device -> iOS -> select a different device
Close the current device from File -> Close Window. Now we have only one window open.
Install expo app on this device by restarting package manger and pressing i again for install.
Now we can open the earlier closed device X again. Open simulator and open the expo app.
The expo URL from step 1 should be in clipboard textarea for the expo app. Launch the app by clicking the URL.
For next time onwards, the picked devices already have an expo app installed.
Do step 1 as above.
Open the default X and the other device Y.
Open e
xpo apps on devices and follow step 7 to run the app on both simulators.
So its much faster the second time onwards.
The downside with this is that logs from both simulators appear in the same terminal. Right now, I have cloned the project in a different directory, and do react-native-scrips start from a different terminal; and use the second expo URL generated in one of the simulators. The logs from both simulators now appear in different terminals. There should be better ways to do this.
PS - I am currently on version 10+ of xcode.