简体   繁体   中英

Share user defaults between users

I'm using user defaults to store my app data.

I have some global data that is relevant for all users on the same machine.

How can I share this data between them?

NSUserDefaults' initWithSuiteName did not work.

The only workaround I found it to write to a hidden file in the root folder, but that is too visible to the users.

The closest you could do is to make all of the users be members of a single group, then make a group writable file with the shared data. It could be a plist and it could even be accessed via the defaults API, assuming you don't need multiple simultaneous write access.

You could use CFPreferences APIs instead of NSUserDefaults , passing kCFPreferencesAnyUser as the user name parameter. However, setting defaults for all users requires admin privileges.

您可以使用/Users/Shared目录,如iTunesApp Store

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