EXC_BAD_ACCESS with NSUserdefaults on iphone.
- by Andreas Johannessen
I have the following code in my ApplicationDelegate. My deployment target is 3.0 and upwards, however I get a EXC_BAD_ACCESS when I launch the app with the following code on my iPhone with 3.1.3, however on the simulator which has 4.2 it runs fine.
I would really appriciate help on this one, thanks in advance.
When I comment this block when I deploy to 3.1.3 device it runs without bad access.
+ (void)initialize {
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *pListPath = [path stringByAppendingPathComponent:@"Settings.bundle/Root.plist"];
NSDictionary *pList = [NSDictionary dictionaryWithContentsOfFile:pListPath];
NSMutableArray *prefsArray = [pList objectForKey:@"PreferenceSpecifiers"];
NSMutableDictionary *regDictionary = [NSMutableDictionary dictionary];
for (NSDictionary *dict in prefsArray) {
NSString *key = [dict objectForKey:@"Key"];
if(key) {
id value = [dict objectForKey:@"DefaultValue"];
[regDictionary setObject:value forKey:key];
}
}
[[NSUserDefaults standardUserDefaults] registerDefaults:regDictionary];
}
UPDATE:
I traced the error to happen on this line:
[[NSUserDefaults standardUserDefaults] registerDefaults:regDictionary];
So there is probaly another syntax on earlier iOS, or am I wrong?