两种应用的一种偏好

发布于 2024-09-30 11:13:37 字数 153 浏览 0 评论 0原文

我有两个带有 id-s 的应用程序:com.myCompany.mayApp 和 com.myCompany.mayAppPro。 如何将一个首选项文件 com.myCompany.mayApp.plist 用于这两个应用程序? 是否可以使用 NSUserDefaults 类来实现此目的?

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 to use class NSUserDefaults for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

活雷疯 2024-10-07 11:13:37

看一下 NSUserDefaults 中的以下方法:

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

它们允许您读取和写入具有给定域名的首选项文件。一个示例是读取 Apple iApp 的一些常见首选项:

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

前面的代码读取 iTunes 数据库文件的最近路径数组。

这些方法的缺点是它们读取和写入文件的全部内容。如果存储的项目数量不是很大,那么这通常不是问题。

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.

巷雨优美回忆 2024-10-07 11:13:37

我认为您必须使用 CFPreference API 来设置共享值,但是您可以读取使用 NSUserDefaults 的值,方法是将套件添加到共享 NSUserDefaults 的搜索路径实例。当然,您也可以使用 CFPreference API 读取这些值。

如果您的首选项很复杂并且您想使用 cocoa 绑定,您也可以编写自己的接口来包装键/值/域/主机/用户配置。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文