开发者

Is there a way to determine the setting of the Ring/Silent switch on the iPhone

开发者 https://www.devze.com 2023-02-11 00:28 出处:网络
I am trying to figure out from my code whether the Ring/Silent switch is on ring or silent. Is there a way to determine this from 开发者_JAVA技巧my program.

I am trying to figure out from my code whether the Ring/Silent switch is on ring or silent. Is there a way to determine this from 开发者_JAVA技巧my program.

Thanks


I did some more searching and found the same question here How to detect iphone is on silent mode.

For completeness, here is the answer from Neil that worked for me?

CFStringRef state = nil;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
OSStatus status = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);

if (status == kAudioSessionNoError) { 
    return (CFStringGetLength(state) == 0);   // YES = silent
}
return NO;

It should be noted that this will not work if headphones are connected. You will always get "HeadPhone". This was also reported by coob.


The answer is no.

You can configure how your audio session is affected by the switch, but you cannot tell whether it's on or off.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号