3

I need to detect if the phone is in silent mode or not. I found old way and new way (playing an .caf file) but none of them worked correctly. Old way uses deprecated tools and new way always give "no" in both cases (silent mode and not).

At this point, can anyone suggest anything?

Community
  • 1
  • 1
anyName
  • 113
  • 1
  • 2
  • 13
  • see this http://stackoverflow.com/questions/35284722/how-can-i-detect-whether-an-ios-device-is-in-silent-mode-or-not – Anbu.Karthik Mar 20 '17 at 07:16
  • You can find your answer here : http://stackoverflow.com/questions/287543/how-to-programmatically-sense-the-iphone-mute-switch – sschunara Mar 20 '17 at 07:16
  • Possible duplicate of [How to detect iphone is on silent mode](http://stackoverflow.com/questions/833304/how-to-detect-iphone-is-on-silent-mode) – Jigar Mar 20 '17 at 07:31
  • @Anbu.Karthik This is in Swift but does not matter, i tried its Objective-C version and not get a good result. – anyName Mar 20 '17 at 08:11
  • @sschunaraThis answer uses the same methods of old way i mentioned. They are all deprecated and not like other deprecaed methods, these don't work correctly. – anyName Mar 20 '17 at 08:13
  • @IOS_DEV Again, audiosessionsinitalize is deprecated and these suggestions not working. – anyName Mar 20 '17 at 08:14

1 Answers1

0

Try the below solution and let me know if it works for you :

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

    }
Pradumna Patil
  • 2,180
  • 3
  • 17
  • 46
  • 1
    No this solution is just like old way and not working because as i told a lot of times, AudioSessionInitialize and getProperty methods are all deprecated. In both way (silent or not) it returns NO. – anyName Mar 20 '17 at 13:19