Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect silent mode in iOS 7

Tags:

ios

iphone

ios7

is there any way to detect silent mode in iOS 7?

the following code does not work for iOS 5 or later version

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

   }
like image 280
sumon Avatar asked Jan 08 '14 10:01

sumon


1 Answers

Check this thread - Detecting the iPhone's Ring / Silent / Mute switch using AVAudioPlayer not working?

And this API - SoundSwitch

How it works:

  • Play an audio file of 0.5 secs, every sec (after completion..)
  • Check how long it took to play the sound
  • Callback called real fast? nothing was played (silent switch is ON)

Enjoy!

like image 98
ignotusverum Avatar answered Oct 17 '22 09:10

ignotusverum