Reputation: 921
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 my program.
Thanks
Upvotes: 1
Views: 781
Reputation: 921
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.
Upvotes: 2
Reputation: 6405
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.
Upvotes: 0