Detect Silent mode in iOS5?

10,234

Solution 1

We won't be able to detect the silent switch state anymore since iOS 5...

The answer from Apple is there on the accepted answer : Detecting the iPhone's Ring / Silent / Mute switch using AVAudioPlayer not working?

Solution 2

As mentioned in the iOS Developer Library, the property kAudioSessionProperty_AudioRoute is deprecated. Instead, Use the kAudioSessionProperty_AudioRouteDescription

https://developer.apple.com/library/ios/#documentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html

This question has been answered here: Detecting the iPhone's Ring / Silent / Mute switch using AVAudioPlayer not working?

Share:
10,234
CCDEV
Author by

CCDEV

Updated on June 24, 2022

Comments

  • CCDEV
    CCDEV almost 2 years

    I have used this method in the past to detect if the silent switch is enabled:

    - (BOOL)silenced {
        #if TARGET_IPHONE_SIMULATOR
        // return NO in simulator. Code causes crashes for some reason.
        return NO;
        #endif
    
        CFStringRef state;
        UInt32 propertySize = sizeof(CFStringRef);
        AudioSessionInitialize(NULL, NULL, NULL, NULL);
        AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);
    
        if(CFStringGetLength(state) > 0)
            return NO;
        else
            return YES;
    }
    

    This is no longer working in iOS5 on my iPad or iPhone. Is this a known issue? I haven't been able to find any answers on stack overflow or Apple dev forums.

    Hope you can help...