1

Possible Duplicate:
How to programatically sense the iPhone mute switch?

I want my app to check wether the mute switch is toggled on or off! But there is one problem... Is there a function for it?

Thanks in advance

4

1 回答 1

0

How to programmatically sense the iPhone mute switch?

I do believe this is what you are looking for.

Posting the code here:

// "Ambient" makes it respect the mute switch
// Must call this once to init session
if (!gAudioSessionInited)
{
    AudioSessionInterruptionListener    inInterruptionListener = NULL;
    OSStatus    error;
    if ((error = AudioSessionInitialize (NULL, NULL, inInterruptionListener, NULL)))
    {
        NSLog(@"*** Error *** error in AudioSessionInitialize: %d.", error);
    }
    else
    {
        gAudioSessionInited = YES;
    }
}

SInt32  ambient = kAudioSessionCategory_AmbientSound;
if (AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (ambient), &ambient))
{
        NSLog(@"*** Error *** could not set Session property to ambient.");
}
于 2011-07-24T16:05:48.047 回答