开发者

One preferences 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 two these applications? Is it possible 开发者_如何学Cto use class NSUserDefaults for this?


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 read and write to a preferences file with a given domain name. An example is to read some common preferences for the Apple iApps:

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

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

The disadvantage of these methods are that they read and write the entire contents of the file. If the number items being stored is not really large then this is not generally a problem.


i think you'll have to use the CFPreference APIs to set shared values, but you can read the values using NSUserDefaults by adding the suite to the search path of the shared NSUserDefaults instance. of course, you may read the values using the CFPreference APIs too.

if your prefs are complex and you want to use cocoa bindings, you may as well write your own interface which wraps the keys/value/domain/host/user config.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜