NSUserDefaults,Settings.bundle和App组 [英] NSUserDefaults, Settings.bundle and App groups

查看:134
本文介绍了NSUserDefaults,Settings.bundle和App组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含2个目标的应用程序,主应用程序和今日扩展程序 - 要在这些目标之间共享设置我已启用应用程序组功能,添加了一个组 group.myApp.com 然后在主应用程序和今日扩展程序中使用 NSUserDefaults ,如此:

I have an app with 2 targets, the main app and a Today extension - to share settings between these targets I've switched on the App Groups Capabilities, added a group group.myApp.com and then using NSUserDefaults like so in both the main app and Today Extension:

var defaults: NSUserDefaults = NSUserDefaults(suiteName: "group.myApp.com")!

(按照此处的说明: http://goo.gl/pNrYQl

这个工作正常。我想在应用程序中添加一个Settings.bundle来更改两个目标中的设置,但这似乎是使用 standardUserDefaults 代表'main'目标,而不是 group.myApp.com 部分。任何想法如何使Settings.bundle使用我的 group.myApp.com 设置'区域'?

This is working fine. I would like to add a Settings.bundle to the app to change settings in both targets but this seems to be using the standardUserDefaults for the 'main' target, not the group.myApp.com section. Any ideas how to make the Settings.bundle use my group.myApp.com settings 'area'?

许多谢谢。

推荐答案

最终在原文链接网站。


定位App-Group设置而不是App Targets用户默认值,
你需要做的就是添加ApplicationGroupContainerIdentifier作为您的设置包的Root.plist的
键,并将其值设置为
您的App-Group标识符

to target App-Group settings instead of the App Targets user defaults, all you need to do is add "ApplicationGroupContainerIdentifier" as a key to the Root.plist of your Settings Bundle and set its value as your App-Group identifier

因此,在我的Settings.Bundle Root.plist中添加以下内容后,我的主应用程序和今日扩展程序都访问了相同的用户默认值。

So, after adding the following to my Settings.Bundle Root.plist, both my main App and Today Extension are accessing the same user defaults.

这篇关于NSUserDefaults,Settings.bundle和App组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆