Using the Low-Level Preferences API
There are some cases where using the high-level API is not appropriate. If you are building some sort of âhelper toolâ that runs on behalf of another application, or an application that stores preferences for other applications, you will need to use the low-level preferences API to write to the other applicationâs preferences. Listing 1 shows you how to do this.
Listing 1 Writing a value to another applicationâs preferences.
CFStringRef appID = CFSTR("com.apple.anotherapp"); |
CFStringRef defaultTextColorKey = CFSTR("defaultTextColor"); |
CFStringRef colorBLUE = CFSTR("BLUE"); |
// Set up the preference. |
CFPreferencesSetValue(defaultTextColorKey, |
colorBLUE, |
appID, |
kCFPreferencesCurrentUser, |
kCFPreferencesAnyHost); |
// Write out the preference data. |
CFPreferencesSynchronize(appID, |
kCFPreferencesCurrentUser, |
kCFPreferencesAnyHost); |
Note that this example writes to another applicationâs preferences. Thereâs no way to get the bundle ID directly from the other application, so itâs necessary to hardcode the application ID.
Copyright © 2003, 2006 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2006-10-03