Mugen
Mugen

Reputation: 9085

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.

Upvotes: 1

Views: 190

Answers (3)

user5309815
user5309815

Reputation: 26

You can use the /Users/Shared directory like iTunes & the App Store.

Upvotes: 1

JWWalker
JWWalker

Reputation: 22707

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

Upvotes: 1

bbum
bbum

Reputation: 162712

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.

Upvotes: 1

Related Questions