In a C# application I always used an app.config
file to save some data for my application to load when needed (e.g Connection String).
What is the best way to save information like this in an iOS application?
An MDM server can push a configuration to the iOS App. The app can access the configuration using the NSUserDefaultsclass. The configuration is basically a key-value dictionary provided as a . plist file.
Overview. A build configuration file is a plain-text file you use to specify the build settings for a specific target or your entire project. Build configuration files make it easier to manage build settings yourself, and to change build settings automatically for different architectures and platforms.
The application configuration file usually lives in the same directory as your application. For web applications, it is named Web. config. For non-web applications, it starts life with the name of App.
You can create a property list file (there is a template for that in XCode, just to to File -> New file and choose there), so you will have something like "settings.plist", or anything like that. You can think of a plist as being a key => value config file, with the difference that you can also hold arrays and dictionaries, besides plain text as value.
Use NSBundle to load the file in your app, like
NSString *path = [[NSBundle mainBundle] pathForResource:@"settings" ofType:@"plist"]; NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:path];
You can then access your keys as a regular dictionary. Just don't forget to [release] it after ;).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With