How to tell if Siri is active during app use

梦想的初衷 提交于 2019-12-10 17:11:34

问题


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?


回答1:


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




回答2:


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);


来源:https://stackoverflow.com/questions/28933944/how-to-tell-if-siri-is-active-during-app-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!