如何访问iphone系统首选项
问题描述:
如何在iPhone应用程序中访问(读取)“全局首选项”。如何访问iphone系统首选项
想法:我的应用程序提供了“键盘点击” - 我想根据用户设置的iPhone设置启用/禁用它们。
但我不知道如何阅读这些设置(也是“静音开关”状态会很有趣)。
答
对于静音开关请看这里。 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的!
谢谢李。苦涩的消息 - 一方面苹果说(用户界面...主题:用户期望什么)... 另一方面,他们不允许访问那些在“用户需求”。 在我的情况下 - 键盘的声音不能取决于用户设置的全局。 “动画声音”不能依赖于“静音开关”。 我使用意味着“音频会话不完全支持”的monotouch,此外我不使用音频会话 - 我只是使用PlaySystemSound – ManniAT 2009-11-28 14:06:33
我认为只要您遵守静音开关设置,您会好起来的。 – 2009-11-28 21:56:17
我的问题,以履行静音开关 - monotouch不提供访问AudioSession(或至少不完整)。我学会了这一点,当我试图实现“背景音频应鸭” – ManniAT 2009-11-29 12:04:14