Framework | CoreFoundation/CoreFoundation.h |
Companion guide | |
Declared in | CFPreferences.h |
Core Foundation provides a simple, standard way to manage user (and application) preferences. Core Foundation stores preferences as key-value pairs that are assigned a scope using a combination of user name, application ID, and host (computer) names. This makes it possible to save and retrieve preferences that apply to different classes of users. Core Foundation preferences is useful to all applications that support user preferences. Note that modification of some preferences domains (those not belonging to the “Current User”) requires Admin privileges—see Authorization Services Programming Guide for information on how to gain suitable privileges.
Unlike some other Core Foundation types, CFPreferences is not toll-free bridged to its corresponding Cocoa Foundation framework class (NSUserDefaults).
Several functions return a preference value as a Core Foundation property list object. You can use the function CFGetTypeID
to determine the value’s type. For more information about property lists, see Property List Programming Topics for Core Foundation.
CFPreferencesCopyAppValue
CFPreferencesCopyKeyList
CFPreferencesCopyMultiple
CFPreferencesCopyValue
CFPreferencesGetAppBooleanValue
CFPreferencesGetAppIntegerValue
Adds suite preferences to an application’s preference search chain.
void CFPreferencesAddSuitePreferencesToApp ( CFStringRef applicationID, CFStringRef suiteID );
The ID of the application to which to add suite preferences, typically kCFPreferencesCurrentApplication
. Do not pass NULL
or kCFPreferencesAnyApplication
. Takes the form of a Java package name, com.foosoft
.
The ID of the application suite preferences to add. Takes the form of a Java package name, com.foosoft
.
Suite preferences allow you to maintain a set of preferences that are common to all applications in the suite. When a suite is added to an application’s search chain, all of the domains pertaining to that suite are inserted into the chain. Suite preferences are added between the “Current Application” domains and the “Any Application” domains. If you add multiple suite preferences to one application, the order of the suites in the search chain is non-deterministic. You can override a suite preference for a given application by defining the same preference key in the application specific preferences.
CFPreferences.h
Writes to permanent storage all pending changes to the preference data for the application, and reads the latest preference data from permanent storage.
Boolean CFPreferencesAppSynchronize ( CFStringRef applicationID );
The ID of the application whose preferences to write to storage, typically kCFPreferencesCurrentApplication
. Do not pass NULL
or kCFPreferencesAnyApplication
. Takes the form of a Java package name, com.foosoft
.
true
if synchronization was successful, otherwise false
.
Calling the function CFPreferencesSetAppValue
is not in itself sufficient for storing preferences. The CFPreferencesAppSynchronize
function writes to permanent storage all pending preference changes for the application. Typically you would call this function after multiple calls to CFPreferencesSetAppValue
. Conversely, preference data is cached after it is first read. Changes made externally are not automatically incorporated. The CFPreferencesAppSynchronize
function reads the latest preferences from permanent storage.
CFPreferences.h
Determines whether or not a given key has been imposed on the user.
Boolean CFPreferencesAppValueIsForced ( CFStringRef key, CFStringRef applicationID );
The key you are querying.
The application’s ID, typically kCFPreferencesCurrentApplication
. Do not pass NULL
or kCFPreferencesAnyApplication
. Takes the form of a Java package name, com.foosoft
.
true
if value of the key cannot be changed by the user, otherwise false
.
In cases where machines and/or users are under some kind of management, you should use this function to determine whether or not to disable UI elements corresponding to those preference keys.
CFPreferences.h
Constructs and returns the list of all applications that have preferences in the scope of the specified user and host.
CFArrayRef CFPreferencesCopyApplicationList ( CFStringRef userName, CFStringRef hostName );
kCFPreferencesCurrentUser
to search the current-user domain, otherwise kCFPreferencesAnyUser
to search the any-user domain.
kCFPreferencesCurrentHost
to search the current-host domain, otherwise kCFPreferencesAnyHost
to search the any-host domain.
The list of application IDs. Ownership follows the Create Rule.
CFPreferences.h
Obtains a preference value for the specified key and application.
CFPropertyListRef CFPreferencesCopyAppValue ( CFStringRef key, CFStringRef applicationID );
The preference key whose value to obtain.
The identifier of the application whose preferences to search, typically kCFPreferencesCurrentApplication
. Do not pass NULL
or kCFPreferencesAnyApplication
. Takes the form of a Java package name, com.foosoft
.
The preference data for the specified key and application. If no value was located, returns NULL
. Ownership follows the Create Rule.
Note that values returned from this function are immutable, even if you have recently set the value using a mutable object.
CFPreferences.h
Constructs and returns the list of all keys set in the specified domain.
CFArrayRef CFPreferencesCopyKeyList ( CFStringRef applicationID, CFStringRef userName, CFStringRef hostName );
The ID of the application whose preferences to search. Takes the form of a Java package name, com.foosoft
.
kCFPreferencesCurrentUser
to search the current-user domain, otherwise kCFPreferencesAnyUser
to search the any-user domain.
kCFPreferencesCurrentHost
to search the current-host domain, otherwise kCFPreferencesAnyHost
to search the any-host domain.
The list of keys. Ownership follows the Create Rule.
CFPreferences.h
Returns a dictionary containing preference values for multiple keys.
CFDictionaryRef CFPreferencesCopyMultiple ( CFArrayRef keysToFetch, CFStringRef applicationID, CFStringRef userName, CFStringRef hostName );
An array of preference keys the values of which to obtain.
The ID of the application whose preferences are searched. Takes the form of a Java package name, such as com.foosoft
.
kCFPreferencesCurrentUser
to search the current-user domain, otherwise kCFPreferencesAnyUser
to search the any-user domain.
kCFPreferencesCurrentHost
to search the current-host domain, otherwise kCFPreferencesAnyHost
to search the any-host domain.
A dictionary containing the preference values for the keys specified by keysToFetch for the specified domain. If no values were located, returns an empty dictionary. Ownership follows the Create Rule.
Note that values returned from this function are immutable, even if you have recently set the value using a mutable object.
CFPreferences.h
Returns a preference value for a given domain.
CFPropertyListRef CFPreferencesCopyValue ( CFStringRef key, CFStringRef applicationID, CFStringRef userName, CFStringRef hostName );
Preferences key for the value to obtain.
The ID of the application whose preferences are searched. Takes the form of a Java package name, such as com.foosoft
.
kCFPreferencesCurrentUser
if to search the current-user domain, otherwise kCFPreferencesAnyUser
to search the any-user domain.
kCFPreferencesCurrentHost
if to search the current-host domain, otherwise kCFPreferencesAnyHost
to search the any-host domain.
The preference data for the specified domain. If the no value was located, returns NULL
. Ownership follows the Create Rule.
This function is the primitive get mechanism for the higher level preference function CFPreferencesCopyAppValue
Unlike the high-level function, CFPreferencesCopyValue
searches only the exact domain specified. Do not use this function directly unless you have a need. All arguments must be non-NULL
. Do not use arbitrary user and host names, instead pass the pre-defined domain qualifier constants.
Note that values returned from this function are immutable, even if you have recently set the value using a mutable object.
CFPreferences.h
Convenience function that directly obtains a boolean preference value for the specified key.
Boolean CFPreferencesGetAppBooleanValue ( CFStringRef key, CFStringRef applicationID, Boolean *keyExistsAndHasValidFormat );
The preference key whose value to obtain. The key must specify a preference whose value is of type Boolean
.
The identifier of the application whose preferences are searched, typically kCFPreferencesCurrentApplication
. Do not pass NULL
or kCFPreferencesAnyApplication
. Takes the form of a Java package name, such as com.foosoft
.
On return, true
if the preference value for the specified key was located and found to be of type Boolean
, otherwise false
.
The preference data for the specified key and application, or if no value was located, false
.
CFPreferences.h
Convenience function that directly obtains an integer preference value for the specified key.
CFIndex CFPreferencesGetAppIntegerValue ( CFStringRef key, CFStringRef applicationID, Boolean *keyExistsAndHasValidFormat );
The preference key whose value you wish to obtain. The key must specify a preference whose value is of type int
.
The identifier of the application whose preferences you wish to search, typically kCFPreferencesCurrentApplication
. Do not pass NULL
or kCFPreferencesAnyApplication
. Takes the form of a Java package name, com.foosoft
.
On return, indicates whether the preference value for the specified key was located and found to be of type int
.
The preference data for the specified key and application. If no value was located, 0
is returned.
CFPreferences.h
Removes suite preferences from an application’s search chain.
void CFPreferencesRemoveSuitePreferencesFromApp ( CFStringRef applicationID, CFStringRef suiteID );
The ID of the application from which to remove suite preferences, typically kCFPreferencesCurrentApplication
. Do not pass NULL
or kCFPreferencesAnyApplication
. Takes the form of a Java package name, com.foosoft
.
The ID of the application suite preferences to remove. Takes the form of a Java package name, com.foosoft
.
CFPreferences.h
Adds, modifies, or removes a preference.
void CFPreferencesSetAppValue ( CFStringRef key, CFPropertyListRef value, CFStringRef applicationID );
The preference key whose value you wish to set.
The value to set for the specified key and application. Pass NULL
to remove the specified key from the application’s preferences.
The ID of the application whose preferences you wish to create or modify, typically kCFPreferencesCurrentApplication
. Do not pass NULL
or kCFPreferencesAnyApplication
. Takes the form of a Java package name, com.foosoft
.
New preference values are stored in the standard application preference location, ~/Library/Preferences/
. When called with kCFPreferencesCurrentApplication
, modifications are performed in the preference domain “Current User, Current Application, Any Host.” If you need to create preferences in some other domain, use the low-level function CFPreferencesSetValue
.
You must call the CFPreferencesAppSynchronize
function in order for your changes to be saved to permanent storage.
CFPreferences.h
Convenience function that allows you to set and remove multiple preference values.
void CFPreferencesSetMultiple ( CFDictionaryRef keysToSet, CFArrayRef keysToRemove, CFStringRef applicationID, CFStringRef userName, CFStringRef hostName );
A dictionary containing the key/value pairs for the preferences to set.
An array containing a list of keys to remove.
The ID of the application whose preferences you wish to modify. Takes the form of a Java package name, com.foosoft
.
kCFPreferencesCurrentUser
to modify the current user’s preferences, otherwise kCFPreferencesAnyUser
to modify the preferences of all users.
kCFPreferencesCurrentHost
to modify the preferences of the current host, otherwise kCFPreferencesAnyHost
to modify the preferences of all hosts.
Behavior is undefined if a key is in both keysToSet and keysToRemove
CFPreferences.h
Adds, modifies, or removes a preference value for the specified domain.
void CFPreferencesSetValue ( CFStringRef key, CFPropertyListRef value, CFStringRef applicationID, CFStringRef userName, CFStringRef hostName );
Preferences key for the value you wish to set.
The value to set for key and application. Pass NULL
to remove key from the domain.
The ID of the application whose preferences you wish to modify. Takes the form of a Java package name, com.foosoft
.
kCFPreferencesCurrentUser
to modify the current user’s preferences, otherwise kCFPreferencesAnyUser
to modify the preferences of all users.
kCFPreferencesCurrentHost
to modify the preferences of the current host, otherwise kCFPreferencesAnyHost
to modify the preferences of all hosts.
This function is the primitive set mechanism for the higher level preference function CFPreferencesSetAppValue
. Only the exact domain specified is modified. Do not use this function directly unless you have a specific need. All arguments except value
must be non-NULL
. Do not use arbitrary user and host names, instead pass the pre-defined constants.
You must call the CFPreferencesSynchronize
function in order for your changes to be saved to permanent storage. Note that you can only save preferences for “Any User” if you have Admin privileges.
CFPreferences.h
For the specified domain, writes all pending changes to preference data to permanent storage, and reads latest preference data from permanent storage.
Boolean CFPreferencesSynchronize ( CFStringRef applicationID, CFStringRef userName, CFStringRef hostName );
The ID of the application whose preferences you wish to modify. Takes the form of a Java package name, com.foosoft
.
kCFPreferencesCurrentUser
to modify the current user’s preferences, otherwise kCFPreferencesAnyUser
to modify the preferences of all users.
kCFPreferencesCurrentHost
to search the current-host domain, otherwise kCFPreferencesAnyHost
to search the any-host domain.
true
if synchronization was successful, false
if an error occurred.
This function is the primitive synchronize mechanism for the higher level preference function CFPreferencesAppSynchronize
; it writes updated preferences to permanent storage, and reads the latest preferences from permanent storage. Only the exact domain specified is modified. Note that to modify “Any User” preferences requires Admin privileges—see Authorization Services Programming Guide.
Do not use this function directly unless you have a specific need. All arguments must be non- NULL
. Do not use arbitrary user and host names, instead pass the pre-defined constants.
CFPreferences.h
Keys used to specify the common preference domains.
const CFStringRef kCFPreferencesAnyApplication; const CFStringRef kCFPreferencesAnyHost; const CFStringRef kCFPreferencesAnyUser; const CFStringRef kCFPreferencesCurrentApplication; const CFStringRef kCFPreferencesCurrentHost; const CFStringRef kCFPreferencesCurrentUser;
kCFPreferencesAnyApplication
Indicates a preference that applies to any application.
Available in Mac OS X v10.0 and later.
Declared in CFPreferences.h
.
kCFPreferencesAnyHost
Indicates a preference that applies to any host.
This domain is currently unsupported.
Available in Mac OS X v10.0 and later.
Declared in CFPreferences.h
.
kCFPreferencesAnyUser
Indicates a preference that applies to any user.
This domain is currently unsupported.
Available in Mac OS X v10.0 and later.
Declared in CFPreferences.h
.
kCFPreferencesCurrentApplication
Indicates a preference that applies only to the current application.
Available in Mac OS X v10.0 and later.
Declared in CFPreferences.h
.
kCFPreferencesCurrentHost
Indicates a preference that applies only to the current host.
Available in Mac OS X v10.0 and later.
Declared in CFPreferences.h
.
kCFPreferencesCurrentUser
Indicates a preference that applies only to the current user.
Available in Mac OS X v10.0 and later.
Declared in CFPreferences.h
.
© 2003, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-10-31)