iOS 8.2 Settings.bundle default value

前端 未结 1 895
心在旅途
心在旅途 2021-01-21 03:14

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\' bac

相关标签:
1条回答
  • 2021-01-21 04:04

    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.

    0 讨论(0)
提交回复
热议问题