tags:

views:

484

answers:

1

How can I access (read) the "global preferences" in an iPhone application.

Idea: my application provides "keyboard clicks" - I want to enable / disable them depening on what the users has set on his iPhone settings.

But I have no idea how to read those settings (also the "mute switch" status would be interesting).

A: 

For the mute switch see here. http://www.restoroot.com/Blog/2008/12/25/audiosessioninitialize-workarounds/

Essentially you are just need this.

// "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 *** GBMusicTrack - initWithPath: error in AudioSessionInitialize: %d.", error);
        }
        else
        {
            gAudioSessionInited = YES;
        }
    }

    SInt32  ambient = kAudioSessionCategory_AmbientSound;
    if (AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (ambient), &ambient))
    {
        NSLog(@"*** Error *** GBMusicTrack - initWithPath: could not set Session property to ambient.");
    }

As for reading system preferences, you can't at least not through public API's!

Lee Armstrong
Thanks Lee.Bitter news - on the one hand apple says (in UI... topic: what a user expects)...And on the other hand they give no access to those settings which are important in "what a user expectes".In my situation - sounds for my keyboard can't depend on what the user set's globally."Animation Sounds" can not depend on the "silent switch".I use monotouch which means "audio session not fully supported", and further I don't use audio sessions - I just use PlaySystemSound
ManniAT
I think as long as you honour the mute switch setting you will be fine.
Lee Armstrong
my problem to honor the mute switch - monotouch doesn't offer access to the AudioSession (or at least not complete). I learned this when I tried to implement "background audio should duck"
ManniAT
one last thing - I gave you link a closer look -- but couldn't find anything about the mute switch there...
ManniAT