Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Application Configuration File

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?

like image 541
António Avatar asked Nov 18 '11 11:11

António


People also ask

What is the name of the iOS app configuration file?

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.

What is configuration file in iOS?

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.

Where is the app config file located?

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.


1 Answers

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 ;).

like image 183
Rafael Steil Avatar answered Oct 06 '22 20:10

Rafael Steil