Open Iphone Simulator Mac

Important:The information in this document is deprecated in Xcode 9. For Xcode 9 and later, see Simulator Help by choosing Help > Simulator Help in Simulator.

Simulator app, available within Xcode, presents the iPhone, iPad, or Apple Watch user interface in a window on your Mac computer. You interact with Simulator by using the keyboard and the mouse to emulate taps, device rotation, and other user actions.

The chapter presents the basics of using Simulator. You can perform these steps using your own iOS app or, if you do not have an app to use, with the HelloWorld sample code. For more detailed information on interacting with Simulator and using it to test and debug your apps, refer to the later chapters in this guide.

Access Simulator from Xcode

Click the Run button to build and run the app on the selected simulated or real device. View the status of the build in the activity area of the toolbar. If the build is successful, Xcode runs the app and opens a debugging session in the debug area. Use the controls in the debug area to step through your code, inspect variables. Install the iOS Simulator. On your Mac, open Xcode. On the Xcode menu bar, select 'Xcode'. Navigate to the 'Preferences' menu option. Click 'Downloads'. In the 'Components' tab, select the iOS Simulator versions that you would like. Click “Install”.

There are two different ways to access Simulator through Xcode. The first way is to run your app in Simulator, and the second way is to launch Simulator without running an app.

Running Your iOS App

When testing an app in Simulator, it is easiest to launch and run your app in Simulator directly from your Xcode project. To run your app in Simulator, choose an iOS simulator—for example, iPhone 6 Plus, iPad Air, or iPhone 6 + Apple Watch - 38mm—from the Xcode scheme pop-up menu, and click Run. Xcode builds your project and then launches the most recent version of your app running in Simulator on your Mac screen, as shown in Figure 1-1.

Note: If you are testing an app with a deployment target of iPad, you can test only on a simulated iPad. If you are testing an app with a deployment target of iPhone or universal, you can test on either a simulated iPhone or a simulated iPad.

Running Your watchOS App

To run your WatckKit app, choose a combination of an iOS device and watchOS device from the Xcode scheme pop-up menu. For example, to run the watch app in a 38mm watch paired with an iPhone 6, choose 'iPhone 6 + Apple Watch - 38mm' from the scheme pop-up menu.

Running the WatchKit target launches two simulators, one for the iOS device and one for the watchOS device. Figure 1-2 shows an iPhone 6 and a 42mm watch running in two different simulators.

Running Your tvOS App

To run your tvOS App, choose a tvOS device from the Xcode scheme pop-up menu. Running the tvOS target launches the most recent version of your app in a simulated new Apple TV device, as shown in Figure 1-3.

Launching Simulator Without Running an App

At times, you may want to launch Simulator without running an app. This approach is helpful if you want to test how your app launches from the Home screen of a device or if you want to test a web app in Safari on a simulated iOS device.

To launch a Simulator without running an app

  1. Launch Xcode.

  2. Do one of the following:

    • Choose Xcode > Open Developer Tool > Simulator.

    • Control-click the Xcode icon in the Dock, and from the shortcut menu, choose Open Developer Tool > Simulator.

To launch a watchOS Simulator without running an app

  1. Launch Xcode.

  2. Do one of the following:

    • Choose Xcode > Open Developer Tool > Simulator (watchOS).

    • Control-click the Xcode icon in the Dock, and from the shortcut menu, choose Open Developer Tool > Simulator (watchOS).

Simulator opens and displays the Home screen of whichever simulated device was last used.

View the Installed Apps

From the Home screen, you have access to all of the apps that are installed in the simulation environment. There are two ways to access the Home screen in Simulator from your app:

  • Press Command-Shift-H.

  • Choose Hardware > Home.

Use the installed apps to test your app’s interaction with them. For example, if you are testing a game, you can use Simulator to ensure that the game is using Game Center correctly.

iOS Device Home Screen

Much like the Home screen on an iOS device, the simulator’s iOS Home screen has multiple pages. After clicking the Home button (or accessing the Home screen through the Hardware menu), you arrive at the second page of the Home screen. To get to the first page, where all of the preinstalled apps are found, swipe to the first Home screen by dragging to the right on the simulator screen.

On the Home screen, you see that all of the apps that have been preloaded into Simulator. See iOS Device Home Screen.

The apps that you see on the Home screen are specific to the iOS device simulation environment. Because Passbook and the Health app are available only for the iPhone, these apps don’t appear if you are simulating a legacy device or an unsupported device type.

watchOS Device Home Screen

The Home screen for a simulated watchOS device behaves the same as it would on an actual device. You can click and drag to simulate the finger dragging around the screen and launch an app by clicking on it. Figure 1-4 shows the home screen of a 42mm watch with a developer app, the Lister sample code.

Use Safari to Test Web Apps

From the Home screen, you can access Safari within Simulator. Use Safari to test your iOS web apps directly on your Mac.

  1. From the Home screen, click Safari.

  2. In the address field in Safari, type the URL of your web app and press the Return key.

If your Mac is connected to the Internet, it displays the mobile version of the URL you specified. For example, type apple.com into the address field and press Return. Safari displays the Apple website. See Figure 1-6.

Use Maps to Simulate Location Awareness

Simulator provides tools to assist you in debugging your apps. One of the many features you can debug in Simulator is location awareness within your app. Set a location by choosing Debug > Location > location of choice. The menu has items to simulate a static location or following a route.

A simulated watchOS device with the location set to None checks the paired iPhone device for the location.

You can specify your own location, which can be seen in the Maps app.

  1. From the Home screen, click Maps.

  2. Choose Debug > Location > Custom Location.

  3. In the window that appears, type the number 40.75 in the latitude field and the number -73.75 in the longitude field.

  4. Click OK.

  5. Click the Current Location button in the bottom-left corner of the simulated device screen.

After completing this task, notice that the blue dot representing your location is in New York, NY, near the Long Island Expressway, as shown in Figure 1-7.

Change the Simulated Device and OS Version

Simulator provides the ability to simulate many different combinations of device type and OS version. A device type is a model of iPhone, iPad, or Apple TV. Some iPhone devices can also have a paired Apple Watch. Each device-OS combination has its own simulation environment with its own settings and apps. Simulator provides simulators for common device-iOS, device-watchOS-iOS device, and device-tvOS combinations. You can also add simulators for a specific combination you want to test. However, not all device type and OS version combinations are available.

Note: To test apps for the iPad mini, use a simulated iPad with the same pixel resolution as the iPad mini.

You can switch between different device-OS combinations. Switching closes the window for the existing device and then opens a new window with the selected device. The existing device goes through a normal OS shutdown sequence, though the timeout might be longer than the one on a real device. The new device goes through a normal OS startup sequence.

To change the simulated device

  1. Choose a Hardware > Device > device of choice.

    Simulator closes the active device window and opens a new window with the selected device.

If the device type and OS version combination you want to use is not in the Device submenu, create a simulator for it.

To add a simulator

  1. Choose Hardware > Device > Manage Devices.

    Xcode opens the Devices window.

  2. At the bottom of the left column, click the Add button (+).

  3. In the dialog that appears, enter a name in the Simulator Name text field and choose the device from the Device Type pop-up menu.

  4. Choose the OS version from the iOS Version pop-up menu.

    Alternatively, if the iOS version you want to use isn’t in the iOS Version pop-up menu, choose “Download more simulators” and follow the steps to download a simulator.

  5. Click Create.

If the OS version you want to use is not installed, download it and follow the steps to add a simulator again.

To download a simulator

  1. In Xcode, choose Xcode > Preferences.

  2. In the Preferences window, click Downloads.

  3. In Components, find the legacy simulator version you want to add, and click the Install button.

You can also delete and rename simulators in the Devices window.

To delete a simulator

  1. In Simulator, choose Hardware > Device > Manage Devices, or in Xcode, choose Window > Devices.

    Xcode opens the Devices window.

  2. In the left column, select the simulator.

  3. At the bottom of the left column, click the Action button (the gear next to the Add button).

  4. Choose Delete from the Action menu.

  5. In the dialog that appears, click Delete.

To rename a simulator, choose Rename from the Action menu and enter a new name.

For how to manage real devices that appear in the Devices window, read Devices Window Help.

Alter the Settings of the Simulated Device

You can alter the settings within Simulator to help test your app.

On a simulated device, use the Settings app. To open the Settings app, go to the Home screen and click or on tvOS, choose Settings. In Figure 1-8 you see the Settings app as it appears when launched in the iOS simulation environment.

The Simulator settings differ from the settings found on a hardware device. Simulator is designed for testing your apps, whereas a hardware device is designed for use. Because Simulator is designed for testing apps, its settings are naturally focused on testing, too. For example, in a simulated iOS device the Accessibility menu provides the ability to turn on the Accessibility Inspector, and the Accessibility menu on a device allows you to turn on and off different accessibility features.

Through the settings, you can test both accessibility and localization of your app. See Testing and Debugging in iOS Simulator for information on how to manipulate your settings for the various types of testing you are interested in.

Remember: Changes made in the Settings app of simulated device affect only the simulation environment that is currently running.

Rotate iOS Devices

You can use Simulator to manipulate the simulated device much as you do a physical device.

To rotate your simulated device, choose Hardware > Rotate Left. When you rotate your simulated device, Settings rotates (see Figure 1-9), just as it would on a hardware device.

Test in Simulator and on a Device

Simulator is designed to assist you in designing, rapidly prototyping, and testing your app, but it should never serve as your sole platform for testing. One reason is that not all apps are available in the simulator. For example, the Camera app is available only on hardware devices and cannot be replicated in the simulator.

In addition, not all bugs and performance problems can be caught through testing in Simulator alone. You’ll learn more about performance differences in Testing and Debugging in iOS Simulator. You can also find more information on testing your app on a device in Launching Your App on Devices in App Distribution Guide.

Quit Simulator

Simulator continues running until you quit it. Quitting Xcode will not close Simulator because they are separate applications. Similarly quitting simulator will not close Xcode.

To quit Simulator, choose Simulator > Quit Simulator. The device is shut down, terminating any running apps.

Note: Both Simulator and watchOS Simulator can be open at the same time.



Copyright © 2018 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2018-02-15

Article Categories:#Process,#Front-end Engineering,#Project Management

Posted on

.

Full interactive iOS Mobile Safari browser testing is possible right on your Mac, no additional services necessary. We'll set up Apple's Simulator and configure it for testing Safari on a wide range of iOS versions and devices.

This article is part of a series on running cross-browser tests directly on your primary computer. The next in the series is Set Up a Windows 10 Virtual Machine and Run Internet Explorer 11 and Edge on Mac or Linux.

Part of preparing most websites and web apps for shipment is testing across devices. Several popular web-based browser testing services make it possible to test iOS's Mobile Safari, but the best of these tools require an additional fee, have limited free features, or restrict the number of users who can use an account at the same time. Apple makes iOS testing available for free to all macOS users, with their Simulator app. The app is hidden away and you need to go through some hoops to support older versions of iOS, but you don't need special technical know-how. Here's how to get it up and running with just a few clicks (and some longish download waits). It works for watchOS and tvOS as well!

Getting Ready

First install XCode, Apple's developer suit. Be prepared for a long download.

Simulator is a standalone app but it's buried deep within the hidden contents of XCode, where you can't get at it, and where Spotlight doesn't see it. So make a symbolic link of it in the Applications folder. Here's how, in case you don't know:

    Enter. Otherwise, skip down to the Addendum for an explanation.

  1. Open up your Applications folder. You should see Simulator! And Spotlight should find it now too! (Note: Spotlight should find it. This stopped working for me the same day I updated from Xcode 9 to Xcode 10. Hopefully Apple fixes this.)

Using Simulator

Open Simulator (double click it from the Applications folder, or open it from Spotlight, or if you're psyched about flexing new-found command line powers run —type and follow with the Enter ⏎ key— the command open /Applications/Simulator.app).

Look at that! An iOS device!

Now you can click on the Safari icon and start browsing! But read on to get the most out of Simulator…

Configuring Simulator

With the devices you need all installed, let's get to know Simulator a little. We'll change the window size, add support for your computer keyboard, and add support for trackpad scrolling.

Turn on the ability to type in Simulator with your keyboard

By default, you have to use the on-screen keyboard to type in Simulator's iOS devices, just like you use the on-screen keyboard on a real iOS device. But you can turn on support for your physical keyboard:

In Simulator's 'Hardware' menu, under 'Keyboard,' check 'Connect Hardware Keyboard.'

Share the clipboard across macOS and your Simulator devices

By default, the standard command v keyboard shortcut will not work to paste to Simulator from any other app. To turn on the shared clipboard (known in Apple devices as the pasteboard), select 'Automatically Sync Pasteboard' from the 'Edit' menu.

Note for users running older versions of Xcode: This worked differently prior to Simulator 10. You'll have to use shift command v to paste the macOS clipboard into the Simulator pasteboard, and then you can use command v to paste from the pasteboard.

Iphone

Switching Devices

With Simulator you can test any Apple device. Select the device you want to use from the 'Device' submenu in the 'Hardware' menu. By default you'll have only the latest version of iOS, tvOS, and watchOS, but you can easily install 'runtimes' for older versions.

Add support for older versions of iOS, tvOS, and watchOS

To add support for other versions of iOS, tvOS, or watchOS, first select 'Manage Devices' from the the 'Hardwear' menu's 'Device' submenu. (For iOS marketshare by version, refer to iOS Distribution and iOS Market Share or Mobile & Tablet iOS Version Market Share Worldwide. Historically, the most recent and second most recent versions of iOS account for between 80–90% of iOS usage, with adoption of the most recent version taking several months to surpass the second most recent version.)

That will open the Xcode app's 'Devices' window. Select the 'Simulators' tab. Then click the + in the bottom left corner. (Note that your window may look different — as of this writing, it has been redesigned in every recent version of XCode. In XCode 9 you'll have to select 'Add Device' from the +'s contextual menu).

Under 'OS Version,' select 'Download more simulator runtimes.'

Another new window opens, Xcode's 'Components' preferences' list of simulators. Click the downward arrow button next to the OS you want to install support for.

When the download is complete, close the window. Back in the 'Create a new simulator' dialog:

  • Leave the 'Simulator Name' field blank.
  • Select the device you want a simulator for.
  • And the OS version you just downloaded should be an option now! (Note that 'OS Version' is limited by 'Device Type,' so you must select the device type first.)

Click 'Create,' and quit Xcode. Back in Simulator, the device you just added should show up in the 'Devices' list!

There you have it! If you aren't familiar with the command line and want to understand what the symbolic link command was doing, continue down to the addendum. Otherwise, you're set up to test things on iOS without going through some extra service!

Limited-audience bonus 1: Turn on three-finger trackpad scrolling in Simulator

By default, you can scroll in a Simulator device by clicking and dragging. With the hardware keyboard connected, you can also use the keyboard arrow keys. If you're used to using trackpad scrolling (e.g. two-finger scrolling) in macOS, you may want to turn it on for Simulator too. While two-finger dragging isn't supported, three-finger dragging is. As of this writing, the experience really isn't good: there can be a initial delay, and then another delay before inertial scrolling kicks in. Here's how to turn it on:

From the System menu () open the 'System Preferences,' and from there, open the 'Accessibility' preferences. Under 'Mouse & Trackpad,' open the 'Trackpad Options' and turn on 'three finger drag.'

Limited-audience Bonus 2: Opening multiple Simulator devices on older versions of Xcode

Sometimes it's useful to have two devices up on the screen at the same time. Before, Xcode 8 (or was it 9?) Simulator could only run one device at a time. If you're on an older version of Simulator that doesn't support multiple devices, you can open two instances of the Simulator app with open -n:

Ios

Ios Simulators

The second instance of the app opens with an error 'Unable to boot device in current state: booted.' That's saying 'the device you're asking to simulate is already being simulated,' which is true — by default it's trying to open the same device as it's running in the first instance of the app. Say OK, then go to the Hardware menu > Device and choose a different device. (h/t i40west for the technique)

Addendum: what's that terminal command doing??

If you aren't familiar with the 'command line,' don't just run a command because someone on the internet says to. I don't know if it's ever really happened (it probably has), but there are plenty of urban legends of command line novices getting tricked into doing serious damage to their computers.

I've said that to make Simulator appear you run

In a nutshell, the Simulator app is installed as part of Xcode, but it's hidden. So we create an alias (aka 'shortcut' to people who learned the term on Windows) to the hidden app, and put the alias in the Applications folder.

Here's how it works:

The 'command line' lets you run programs that don't have an interface — you tell the app what to do with text commands rather than by clicking on things. The first thing you write is the name of the command. Here, we're running ln, a command that creates links, the technical name for aliases (ln is short for 'link').

Open Iphone Simulator Mac Os

Open Iphone Simulator Mac

Next, write the command-specific options. Option are set with 'flags' prefixed with -. ln's -s flag turns on ln's 'symbolic link' option. There are important differences between symbolic links and plain old links, but in this context what matters is that apps cannot be aliased with a link; apps must be aliased with a symbolic link.

The next thing ln needs to be told is the thing you want to create an alias to (the 'source file'). All files on your computer have an address, written in the form folder/subfolder/file where in a/b/c 'c' is inside 'b' which is inside 'a'. This should look familiar from website URLs, and it's actually exactly the same: a website's URL reflects an actual folder structure on a computer somewhere. [More or less… That used to be a given; now it's only sometimes mostly true.] In our case, Xcode is in the 'Applications' folder, and insideXcode there's a Contents folder, and in that is a Developer folder, and in that is an Applications folder, and the Simulator app is in that.

Open Iphone Simulator Mac Version

Next you specify the place ln should put that alias (the 'target directory'). It makes sense to put your alias to Simulator in the 'Applications' folder: add a space after the source file's path, and then write /Applications. (See that / in front of /Applications, in both the source file and the target directory? That's saying 'this is at the top level' - Xcode is a child of 'Applications' but 'Applications' is not the child of anything. One last bit of vocab: 'Applications' is the parent of Xcode.)

Ios Simulator For Mac

Okay, hit Enter!