One preference for two applications

I have two applications with id-s: com.myCompany.mayApp and com.myCompany.mayAppPro. How can I use one pref file com.myCompany.mayApp.plist for these two applications? Can the NSUserDefaults class be used for this?

+4
source share
2 answers

Take a look at the following methods in NSUserDefaults:

- (NSDictionary *)persistentDomainForName:(NSString *)domainName; - (void)setPersistentDomain:(NSDictionary *)domain forName:(NSString *)domainName; - (void)removePersistentDomainForName:(NSString *)domainName; 

They allow you to read and write to the settings file with a given domain name. An example is reading some general settings for Apple iApps:

 NSUserDefaults* prefs = [ NSUserDefaults standardUserDefaults ]; NSDictionary* iAppsPrefs = [ prefs persistentDomainForName: @"com.apple.iApps" ]; NSArray* recentPaths = [ iAppsPrefs objectForKey: @"iTunesRecentDatabasePaths" ]; 

The previous code reads an array of the latest paths for iTunes database files.

The disadvantage of these methods is that they read and write the entire contents of the file. If the stored item numbers are not very large, this is usually not a problem.

+5
source

I think you'll have to use the CFPreference APIs to set common values, but you can read the values ​​using NSUserDefaults by adding a set to the search path for the shared instance of NSUserDefaults. Of course, you can read the values ​​using the CFPreference API.

if your prefs are complex and you want to use cocoa bindings, you can write your own interface that wraps the configuration of keys / values ​​/ domain / host / user.

0
source

All Articles