iOS 8.2 Settings.bundle default value
Asked Answered
I

1

3

I have an application with a Settings.bundle file. I added a default value to a specific field, but whenever I want to read this in the application on iOS 8.2, I get 'nil' back. However when I do this on iOS 7.1 (basically every version below iOS 8.2), I get the correct default value.

Does anyone know if there has been changed something in iOS 8.2 that is causing this and how to fix this? I've already deleted the app and built again. Maybe a small note, I build with Xcode 5. But that doesn't make any difference if I'm using Xcode 5 or Xcode 6. Tested this.

Code: How I retrieve the default value:

id settings = [NSUserDefaults standardUserDefaults];
[settings objectForKey:@"defaultValueUrl"];

Settings.bundle: http://i62.tinypic.com/10nrmhd.png

Thanks!

Immortal answered 20/3, 2015 at 10:7 Comment(0)
U
4

The default values in your Settings bundle are not written to your app’s NSUserDefaults until the user actually goes to Settings and changes them. This has always been the case. Not sure why it was “working” for you before—maybe you never uninstalled the app from device and it kept the old settings around?

What you should do in your code, is to register default settings at startup. (Yes, this is somewhat duplicating what’s going on in your Settings bundle. That’s life.)

[[NUSUserDefaults standardDefaults] registerDefaults:
@{ @"defaultValueURL": @"http://example.com" }];

Now, this defaults key will always have the correct default value, with or without Settings bundle.

Read this post for more info.

Unwonted answered 20/3, 2015 at 10:15 Comment(1)
Thank you! Strange that it worked before, even after clean install of the app. But this solved the problem for me. Thank you very much!Immortal

© 2022 - 2024 — McMap. All rights reserved.