2009-11-27 106 views
3

如何在iPhone應用程序中訪問(讀取)「全局首選項」。如何訪問iphone系統首選項

想法:我的應用程序提供了「鍵盤點擊」 - 我想根據用戶設置的iPhone設置啓用/禁用它們。

但我不知道如何閱讀這些設置(也是「靜音開關」狀態會很有趣)。

回答

0

對於靜音開關請看這裏。 http://www.restoroot.com/Blog/2008/12/25/audiosessioninitialize-workarounds/

基本上你只是需要這個。

// "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."); 
    } 

至於閱讀系統首選項,你不能,至少不是通過公共API的!

+0

謝謝李。苦澀的消息 - 一方面蘋果說(用戶界面...主題:用戶期望什麼)... 另一方面,他們不允許訪問那些在「用戶需求」。 在我的情況下 - 鍵盤的聲音不能取決於用戶設置的全局。 「動畫聲音」不能依賴於「靜音開關」。 我使用意味着「音頻會話不完全支持」的monotouch,此外我不使用音頻會話 - 我只是使用PlaySystemSound – ManniAT 2009-11-28 14:06:33

+0

我認爲只要您遵守靜音開關設置,您會好起來的。 – 2009-11-28 21:56:17

+0

我的問題,以履行靜音開關 - monotouch不提供訪問AudioSession(或至少不完整)。我學會了這一點,當我試圖實現「背景音頻應鴨」 – ManniAT 2009-11-29 12:04:14