使用InAppSettingsKit时读取设置时出现问题 [英] Having problems reading settings while using InAppSettingsKit
问题描述
我使用 InAppSettingsKit
模块来管理我的设置。
I am using the InAppSettingsKit
modules to manage my settings.
我可以将它包含在我的项目中我可以构建一个与我的项目正确交互的设置页面。我有一个root.plist,我可以更改,当我第一次在模拟器上运行我的应用程序时,我可以看到反映的更改。
I can include it in my project to the point where I can build a settings page that interacts correctly with my project. I have a root.plist that I can change and when I first run my app on the simulator I can see the changes reflected.
但是,就我而言,我无法通过我的代码访问 NSUserDefaults
中的设置。当我运行下面的代码时,我可以循环遍历 [NSUserDefaults standardUserDefaults]
的内容。但是,我只看到一堆与我的plist文件中的内容无关的通用设置
However, for the life of me, I cannot access the settings in NSUserDefaults
through my code. When I run the code below I can loop through the contents of the [NSUserDefaults standardUserDefaults]
. However, I only see a bunch of generic settings that are not related to the stuff in my plist file
NSUserDefaults* d = [NSUserDefaults standardUserDefaults];
NSDictionary* dict = [d dictionaryRepresentation];
NSString* descKey;
NSString* descObject;
NSString* classTypeForKey;
NSString* classTypeForObject;
id myObject;
for (id key in dict) {
myObject = [dict objectForKey:key];
classTypeForObject = [[myObject class] description];
classTypeForKey = [[key class] description];
descKey = [key description];
descObject = [myObject description];
}
那么InAppSettingsKit将设置放在哪里?该文档在 [NSUserDefaults standardUserDefaults]
中说,所以我不知所措。
So where does InAppSettingsKit put the settings? The doc says in [NSUserDefaults standardUserDefaults]
so I am at a loss.
推荐答案
我认为你的问题依赖于对这个概念的误解。 Root.plist不存储任何设置,只是定义了Settings.app和InAppSettingsKit如何处理你的userDefaults。
I think your problem relies on a misunderstanding of the concept. Root.plist doesn't store any settings but just defines how Settings.app and InAppSettingsKit work on your userDefaults.
当你的应用第一次启动时,没有userDefaults 。通常,您可以通过从资源中读取静态 userDefaults.plist
来设置适当的默认设置:
When your app launches the first time, there are no userDefaults. Usually, you start by setting appropriate default settings by reading in a static userDefaults.plist
from your Resources:
// Load the default values for the user defaults
NSString* pathToUserDefaultsValues = [[NSBundle mainBundle]
pathForResource:@"userDefaults"
ofType:@"plist"];
NSDictionary* userDefaultsValues = [NSDictionary dictionaryWithContentsOfFile:pathToUserDefaultsValues];
// Set them in the standard user defaults
[[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValues];
这篇关于使用InAppSettingsKit时读取设置时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!