MScottWaller
MScottWaller

Reputation: 3573

How to tell if Siri is active during app use

I have an audio app, and when AVAudioSessionRouteChangeNotification comes on, the app configures AV and tests for headphone use and such.

However, Siri activates the AVAudioSessionRouteChangeNotification, but because of the AV configuration, Siri isn't able to be used by the user (the microphone doesn't work for her, it seems.)

Is there a way to find out if Siri is the thing causing the AVAudioSessionRouteChangeNotification, so that I don't call the method to configure AV if it's Siri and thus let the user use Siri?

Upvotes: 4

Views: 1190

Answers (2)

huynguyen
huynguyen

Reputation: 7760

And use below code in AVAudioSessionRouteChangeNotification event if you want to check Siri start or finish:

AVAudioSessionRouteChangeReason routeChangeReason = [note.userInfo[AVAudioSessionRouteChangeReasonKey] integerValue];
AVAudioSessionRouteDescription* description = note.userInfo[AVAudioSessionRouteChangePreviousRouteKey];

BOOL isSiriStart = (routeChangeReason == AVAudioSessionRouteChangeReasonCategoryChange && description.inputs == nil);
BOOL isSiriFinish = (routeChangeReason == AVAudioSessionRouteChangeReasonCategoryChange && description.inputs != nil);

Upvotes: 0

onmyway133
onmyway133

Reputation: 48155

You're right, both headphone plugging in/out and Siri activating will trigger AVAudioSessionRouteChangeNotification, however, notice the AVAudioSessionRouteChangeReasonKey associated with the notification

When headphone is plugged in, the reason is AVAudioSessionRouteChangeReasonNewDeviceAvailable

When headphone is plugged out, the reason is AVAudioSessionRouteChangeReasonOldDeviceUnavailable

When Siri is activated, the reason is AVAudioSessionRouteChangeReasonCategoryChange

Upvotes: 2

Related Questions