2

I'm trying to detect user's device is silenced or not ( button on the side of the phone ). I found this method to detect this, but AudioSessionGetProperty is deprecated in iOS7.

- (BOOL)deviceIsSilenced {    
    CFStringRef state;
    UInt32 propertySize = sizeof(CFStringRef);
    OSStatus audioStatus = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);
    if (audioStatus == kAudioSessionNoError) {
        NSLog(@"audio route: %@", state) // "Speaker" regardless of silent switch setting, but "Headphone" when my headphones are plugged in
        return (CFStringGetLength(state) <= 0);
    }
    return NO;
}

Anyone got a solution for this?

Magyar Miklós
  • 4,182
  • 2
  • 24
  • 42

1 Answers1

0

According to Sound Switch, there is no public API to detect the state of the silent switch, but they provide a hack (using public APIs and therefore believed to be OK for Ap Store approval, but still to be treated with caution):

http://sharkfood.com/content/Developers/content/Sound%20Switch/

Clafou
  • 15,250
  • 7
  • 58
  • 89