开发者

Can Settings bundle use values from application's Info.plist file?

开发者 https://www.devze.com 2023-02-05 04:00 出处:网络
is it possible to开发者_StackOverflow社区 use values from application\'s Info.plist file as DefaultValue value for items in Settings.bundle? For example CFBundleVersion. I\'ve tried entering it as ${C

is it possible to开发者_StackOverflow社区 use values from application's Info.plist file as DefaultValue value for items in Settings.bundle? For example CFBundleVersion. I've tried entering it as ${CFBundleVersion} but it didn't work. I've also tried changing DefaultValue type but with no success. Any ideas?

The reasons behind are simple:

  • CFBundleVersion is known at compile time, so I won't have to take its value from application's mainBundle and then apply that value to NSUserDefaults.
  • Other reason is that just after installing the app, but before running it, Settings bundle values are not in-sync as the code setting NSUserDefaults did not have a chance to execute itself... so it would be boring to always remember that I have to change my Settings bundle values manually.


This is how I synchronize my app's version to use in my Settings.bundle

[defaults setObject:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] forKey:@"kVersion"];
[defaults synchronize];

I place that piece of code in my didFinishLaunchingWithOptions: app delegate, so every time the app launches it makes sure that the correct version is displayed in my Settings.bundle. This takes the app version value from your info.plist

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号