我已经检查了this & this以及其他与 相关的问题InAppSettingsKit
,但无法找到解决方案。
我已经下载了使用InAppSettingsKit进行设置的LinPhone 。现在,我的要求是我必须在登录后仅更改一个特定情况的设置,并且对于所有其他情况都是如此。
请指导我,我该如何更改该案例的设置以及在哪里?
问问题
235 次
1 回答
0
这是一个简短的例子:
// The name of the settings file, currently this plugin use the InAppSettings.bundle
NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"InAppSettings" ofType:@"bundle"];
if(!settingsBundle) {
NSLog(@"Could not find Settings.bundle");
return;
}
NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[settingsBundle stringByAppendingPathComponent:@"Root~iphone.inApp.plist"]];
NSArray *preferences = [settings objectForKey:@"PreferenceSpecifiers"];
NSMutableDictionary *defaultsToRegister = [[NSMutableDictionary alloc] initWithCapacity:[preferences count]];
for(NSDictionary *prefSpecification in preferences) {
NSString *key = [prefSpecification objectForKey:@"Key"];
if(key) {
[defaultsToRegister setObject:[prefSpecification objectForKey:@"DefaultValue"] forKey:key];
}
}
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsToRegister];
[defaultsToRegister release];
[[NSUserDefaults standardUserDefaults] synchronize];
因此,您可以在午餐时将其放在 AppDelegate 中以获取设置。然后您可以使用更改与键关联的值NSUserDefaults
检索示例:
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
CGFloat fontSize = 15;
if(standardUserDefaults){
fontSize = (CGFloat)[[standardUserDefaults objectForKey:@"fontSize"] floatValue];
if(fontSize == 0)
fontSize = 15;
}
通知控制器设置更改
要查看是否修改了某些设置,请将其放入viewDidLoad
您想要通知的控制器中:
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(defaultsChanged:)
name:NSUserDefaultsDidChangeNotification
object:nil];
你只需要实现这个功能defaultsChanged
。
于 2014-02-20T12:48:16.807 回答