User guide
●
What the previous route was
The keys for the dictionary are AVAudioSessionRouteChangeReasonKey and
AVAudioSessionRouteChangePreviousRouteKey. The various reasons why a hardware audio route might
have changed—accessed by the AVAudioSessionRouteChangeReasonKey key—are listed and described
in AVAudioSessionRouteChangeReason. The previous route information—accessed by the
AVAudioSessionRouteChangePreviousRouteKey key—is an object that describes the audio route setting
from before the route change.
One reason for the audio hardware route change in iOS is
AVAudioSessionRouteChangeReasonCategoryChange. In other words, a change in audio session category
is considered by the system—in this context—to be a route change, and will invoke a route change notification.
As a consequence, if your notification response method is intended to respond only to headset plugging and
unplugging, it should explicitly ignore this type of route change.
Here’s a practical example. A well-written recorder/playback app sets the audio session category when beginning
playback or recording. Because of this, a route-change notification is sent upon starting playback (if you were
previously recording) or upon starting recording (if you were previously playing back). Clearly, such an app
should not pause or stop each time a user taps Record or Play. To avoid inappropriate pausing or stopping,
the method called upon receipt of the notification should branch based on the reason for the route change
and simply return if it was a category change. In this case, the category change is from the system’s perspective
and not the app’s perspective.
Responding to Route Changes
Responding to Audio Hardware Route Changes
2014-09-17 | Copyright © 2014 Apple Inc. All Rights Reserved.
39