// 将字典导出到xml
void dumpDict(CFDictionaryRef dict){
CFDataRef xml = CFPropertyListCreateXMLData(kCFAllocatorDefault, (CFPropertyListRef)dict);
if (xml) {
write(1, CFDataGetBytePtr(xml), CFDataGetLength(xml));
CFRelease(xml);
}
}
// 调用demo
int main(int argc, const char * argv[]) {
CFStringRef myName = CFSTR("com.chinapyg.SystemConfigurationTest");
CFArrayRef keyList;
SCPreferencesRef prefs = NULL;
CFIndex i;
// 打开一个选项配置的会话
prefs = SCPreferencesCreate(NULL, myName, NULL);
if (!prefs) {
fprintf(stderr, "SCPreferencesCreate");
exit(1);
}
// 获得选项配置的名称空间
keyList = SCPreferencesCopyKeyList(prefs);
if (!keyList) {;
fprintf(stderr, "CopyKeyList failed\n");
exit(2);
}
// 导出
for (i = 0; i < CFArrayGetCount(keyList); i++) {
dumpDict(SCPreferencesGetValue(prefs, CFArrayGetValueAtIndex(keyList, i)));
}
}
发表评论