EXC_BAD_ACCESS with NSUserdefaults on iphone.

Posted by Andreas Johannessen on Stack Overflow See other posts from Stack Overflow or by Andreas Johannessen
Published on 2011-01-03T19:47:13Z Indexed on 2011/01/03 19:53 UTC
Read the original article Hit count: 232

Filed under:

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?

© Stack Overflow or respective owner

Related posts about iphone