Viewing the app using the Ionic CLI
So far, you have been testing the web app portion of Ionic. Most of the time, you will need to actually run the app on a physical device or at least an emulator to see how the app behaves and whether all native features work.
Getting Ready
You will need to have the emulator installed. iOS emulator comes when you do npm install -g ios-sim
and the Android emulator comes with Android Studio. To test the app on a physical device, you must connect the device to your computer via a USB connection.
How to do it…
- Add the specific platform (such as iOS) and build the app using the following command line:
$ ionic platform add ios $ ionic build ios
Note
Note that you need to do the
platform add
before building the app. However, if you use the standard template from the Ionic CLI, it should already have the iOS platform included. To build and run for Android, you can replace iOS with Android. - To emulate the app using the iOS emulator, use the following command line:
$ ionic emulate ios
- To run the app on the actual physical iPhone device, use the command line as shown:
$ ionic run ios --device