简体   繁体   English

与应用程序和扩展程序共享时,UserDefaults数据存储在哪里?

[英]Where is the UserDefaults data stored when sharing it with app and extension?

I have created an application which uses "UserDefaults" for storing the data. 我创建了一个使用“ UserDefaults”存储数据的应用程序。 I am using the App Groups capability to share the data between the host app and extension. 我正在使用“应用程序组”功能在主机应用程序和扩展程序之间共享数据。 Where can I see the data stored in it? 在哪里可以看到其中存储的数据?

When using the default (UserDefaults.standard) UserDefaults I am able to see the data stored under "Library -> Preferences -> appbundlename.plist. 使用默认(UserDefaults.standard)UserDefaults时,我可以看到存储在“库->首选项-> appbundlename.plist”下的数据。

The application is displaying the data even when I kill it from background.(data is persisting) 即使我从后台杀死数据,该应用程序仍在显示数据。(数据正在保留)

let sharedDefaults = UserDefaults(suiteName: ListManager.GroupId)
let groupPath = FileManager().containerURL(forSecurityApplicationGroupIdentifier: ListManager.GroupId)!.appendingPathComponent("Library/Preferences")

Will get you the path to the shared group defaults. 将为您提供共享组默认路径。 Just be sure to enable the App Groups capabilities for your app (and extensions). 只要确保为您的应用程序(和扩展名)启用应用程序组功能即可。 Otherwise, your group defaults will just appear in the same directory as the standard user defaults (and thus persisting between launches) but will be inaccessible by your other apps or extensions. 否则,您的组默认设置将与标准用户默认设置显示在同一目录中(并因此在两次启动之间保持不变),但其他应用或扩展程序将无法访问它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM