简体   繁体   中英

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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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