User guide

Running Your App in the Simulator
When you add audio session support to your app, you can run your app in the Simulator or on a device.
However, the Simulator does not simulate audio session behavior and does not have access to the hardware
features of a device. When running your app in the Simulator, you cannot:
Invoke an interruption
Change the setting of the Silent switch
Simulate screen lock
Simulate the plugging in or unplugging of a headset
Query audio route information or test audio session category behavior
Test audio mixing behavior—that is, playing your audio along with audio from another app (such as the
Music app)
Because of the characteristics of the Simulator, you may want to conditionalize your code to allow partial
testing in the Simulator.
One approach is to branch based on the return value of an API call. Ensure that you are checking and
appropriately responding to the result codes from all of your audio session function calls; the result codes may
indicate why your app works correctly on a device but fails in the Simulator.
In addition to correctly using audio session result codes, you can employ preprocessor conditional statements
to hide certain code when it is running in the Simulator. Listing 4-4 shows how to do this.
Listing 4-4 Using preprocessor conditional statements
#if TARGET_IPHONE_SIMULATOR
#warning *** Simulator mode: audio session code works only on a device
// Execute subset of code that works in the Simulator
#else
// Execute device-only code as well as the other code
#endif
Optimizing Your App for Device Hardware
Running Your App in the Simulator
2014-09-17 | Copyright © 2014 Apple Inc. All Rights Reserved.
36