views:

1441

answers:

3

I am developing one application. In that I want to detect through coding that "is iphone on silent mode or not?". I am developing it by using cocoa with objective-c.

If anyone knows it kindly reply.

+1  A: 

It's possible by testing for a NULL audio route using AudioToolBox:

UInt32 routeSize = sizeof (CFStringRef);
CFStringRef route;

AudioSessionGetProperty (
                         kAudioSessionProperty_AudioRoute,
                         &routeSize,
                         &route
                        );

if (route == NULL) {
    NSLog(@"Silent switch is on");
}

If route is NULL then there's no available audio outputs. If it's "Headset" or "Headphones" then the silent ringer switch could still be on. However, it will never be on when it's set to "Speaker".

You're probably best testing for this in your audio route change property listener, which is set below:

AudioSessionAddPropertyListener (
                                 kAudioSessionProperty_AudioRouteChange,
                                 audioRouteChangeListenerCallback,
                                 self
                                 );

Note: If you're doing anything funky like overriding audio routes, then this answer may not apply.

Setting up and tearing down an audio session in its entirety is probably beyond the scope of this answer.

coob
Thank you very much coob.I will check it and let you know.
Jyotsna
Did this work OK for you?
coob
A: 

hi, does it work for you ???? atleast if someone helped, people should reply with something like , it is working or it is not working lots of people are looking for the answers that might help them to continue with the replies.

Naren
A: 

Checking for null somehow did not work for me. I used the method that was described here, similar but checks length instead.

http://randomsnippetsofusefulstuff.blogspot.com/

Works great now!