Testing and Debugging in iOS Simulator

iOS Simulator is a great tool for rapid prototyping and development before testing your app on a device. iOS Simulator also has features that can assist you in testing and debugging both iOS apps and web apps. By understanding the tools that iOS Simulator offers, you can more efficiently develop your app.

Limitations of Testing in iOS Simulator

Even though iOS Simulator is a useful tool, never make it the only way you test an app. Because iOS Simulator is an app running on a Mac, it has access to the computer’s memory, which is much greater than the memory found on a device. As a result of the increased memory, iOS Simulator is not an accurate test of an app’s memory usage. For this same reason, you should always test the performance of your app’s user interface (UI) on a device. In iOS Simulator, your app’s UI may appear to run both faster and smoother than on a device.

Also keep in mind that some UI elements can be easier to interact with in iOS Simulator using a mouse than when trying to interact with the app via touch on a device.

Finally, there are some hardware and API limitations of iOS Simulator. These limitations may affect your app when testing in iOS Simulator.

Hardware Limitations

While most of the functionality of iOS devices can be simulated in iOS Simulator, there are some hardware features that must be tested directly on a device. The hardware features that cannot be simulated are:

  • Accelerometer

  • Gyroscope

  • Camera

  • Proximity Sensor

  • Microphone Input

To test your app on a device, you must be a member of the iOS Developer Program. To learn more about enrolling in the iOS Developer Program, see “Enrolling in an Apple Developer Program and Accessing Its Tools”.`

API Limitations

Within iOS Simulator, there are some limitations to the APIs and features, including:

  • Apple Push Services

  • Privacy alerts for access to Photos, Contacts, Calendar, and Reminders

  • The UIBackgroundModes key

  • iCloud document syncing and key-value storage support

Unsupported frameworks include:

  • External Accessory

  • Media Player

  • Message UI

  • Event Kit

  • In UIKit, the UIVideoEditorController class

  • Store Kit

iOS Version Limitations

iOS Simulator app does not have complete backward compatibility. How far back you can go is dependent on what version of OS X your computer is running. Computers running Mac OS X v10.8 support legacy simulators back to iOS 5.0, and computers running Mac OS X v10.7 can support legacy simulators back to iOS 3.4.

To use iOS Simulator for iOS 6.0, you must be running Xcode 4.5.

Testing for the iPad mini

Although an iPad mini isn’t an option for a simulated device in iOS Simulator, you can still test apps for the iPad mini in the simulator. To do this, run your app on the simulated iPad without Retina display.

Testing App Accessibility

Use the Accessibility Inspector to test the accessibility of your app. The Accessibility Inspector displays accessibility information about each accessible element in an app. In Figure 3-1 you can see what the Accessibility Inspector looks like as it runs in iOS Simulator.

Figure 3-1  The Accessibility Inspector running on a simulated iPhone
bullet
To start the Accessibility Inspector
  1. When iOS Simulator is running, click the Home button to reveal the Home screen.

  2. Click Settings.

  3. Go to General > Accessibility.

  4. Slide the Accessibility Inspector switch to On.

Turning on the Accessibility Inspector in iOS Simulator alters the behavior of the simulator. After the Accessibility Inspector is on, clicking an element moves the focus of the inspector to that element instead of activating it. To activate an element, you must double-click it. Additionally, swiping and dragging gestures are unsupported while the Accessibility Inspector is running. To perform these gestures, you must first disable the Accessibility Inspector. To disable and re-enable the Accessibility Inspector, click the close control in the upper-left corner of the inspector panel (the close control looks like a circle with an “X” in it).

For more information on using the Accessibility Inspector and testing the accessibility of your app, see Verifying App Accessibility on iOS.

Testing App Localization

If you have created an app with multiple localizations, you can test them in iOS Simulator by changing the Internationalization settings.

bullet
To change the language of a simulation environment
  1. Build and run your app in iOS Simulator.

  2. Select the simulation environment whose settings you want to change by choosing Hardware > Version > iOS version.

  3. Click the Home button to reveal the Home screen, and click Settings.

  4. Go to General > International > Language.

  5. Select the language, and click Done.

For more information on localizing your app, see Internationalization Programming Topics.

Testing Web Apps

If you are building a web app and want to test its usability on an iOS device, let iOS Simulator assist you.

bullet
To test a web app in iOS Simulator
  1. Select the simulator environment you would like to test in by choosing Hardware > Version > iOS version.

  2. Open Safari from the Home screen of iOS Simulator.

  3. Navigate to the location of your web app in the browser.

For more information on creating web apps for iOS, see Getting Started with iOS Web Apps.

Testing Bluetooth Support

You can use iOS Simulator to test Bluetooth-enabled apps without the use of a Bluetooth LE–capable device. Here’s what you need to proceed:

If your Mac has Bluetooth 4.0 built in, you still need to have a Bluetooth LE USB adapter to test your Bluetooth app.

bullet
To set up Bluetooth support for iOS Simulator
  1. Set the NVRAM setting.

    Open a Terminal window and type the following NVRAM command:

    user$ sudo nvram bluetoothHostControllerSwitchBehavior="never"

    A system restart is not required after changing this setting.

  2. Attach the Bluetooth LE USB adapter to your Mac.

    The Bluetooth LE USB adapter must be connected after issuing the NVRAM command.

  3. Verify the NVRAM setting using the System Information utility.

    You’ll find System Information in the Utilities folder within your Applications folder. Select Bluetooth within the Hardware menu and verify that the Vendor ID is 0x5AC.

    image: ../Art/sysinfo1_2x.png
  4. If the system Bluetooth controller is matched to the Bluetooth LE USB adapter, then iOS Simulator cannot use the external Bluetooth controller for Bluetooth LE services. In this case, you might see a System Information Bluetooth panel like this:

    image: ../Art/sysinfo2_2x.png

    Here, the Bluetooth driver is matched to the Cambridge Silicon Radio (CSR) Bluetooth LE USB adapter. If this is the case, remove the adapter and return to step 1.

  5. Enable Bluetooth in iOS Simulator.

    In Xcode, launch your app in iOS Simulator. When iOS Simulator opens, close the app to return to the Home screen, and open the Settings app. Select the General tab and then verify that Bluetooth is on.

    Relaunch the iOS app in the simulator. The iOS Core Bluetooth app should connect and communicate with Bluetooth LE devices, as it does when run on an iOS device with Bluetooth LE support.

Using the Debugging Tools in iOS Simulator

Access the debugging tools in iOS Simulator through the Debug menu, as shown in Table 3-1.

Table 3-1  Performing debugging through the iOS Simulator Debug menu

Menu item

Debug result

Toggle Slow Animations

Slows down the animation taking place within the app. Use to identify any problems in the animation. Toggle Slow Animations can also be activated by pressing the Shift key three times.

Color Blended Layers

Shows blended view layers. Multiple view layers that are drawn on top of each other with blending enabled are highlighted in red. Reduce the amount of red in your app when this option is selected to dramatically improve your app’s performance. Blended view layers are often the cause of slow table scrolling.

Color Copied Images

Shows images that are copied by Core Animation in blue.

Color Misaligned Images

Places a yellow overlay over images whose source pixels are not aligned to the destination pixels.

Color Off Screen Rendered

Places a magenta overlay on content that is rendered offscreen.

Location

Allows you to set the Core Location to be used by your app. Choose from the different location settings:

  • None. Does not return a location. Use for testing how an app responds when no location data is available.

  • Custom Location. Allows use of a custom latitude and longitude.

  • Apple Stores. Uses the coordinates for an Apple Retail Store.

  • Apple. Uses the coordinates of the Apple Headquarters.

  • City Bicycle Ride. Simulates a bike ride in Cupertino, CA. This option simulates the device moving on a predefined route.

  • City Run. Simulates a run in Cupertino, CA. This option simulates the device moving on a predefined route.

  • Freeway Drive. Simulates a drive through Cupertino, CA. This option simulates the device moving on a predefined route.

Viewing Crash Logs

If your app experiences a problem that causes it to crash, a crash log can help you determine what problem occurred. You open the crash log using Console.

bullet
To view a crash log
  1. Open Console by going to Applications/Utilities/Console in the Finder.

  2. Look for the line in Console that reads “Saved Crash Report for.”

  3. Expand this item using the arrow at the left.

  4. Click Open Report.


Did this document help you? Yes It's good, but... Not helpful...