Can't edit IORegistryEntry

不想你离开。 提交于 2019-12-11 03:04:13

问题


I am creating a software on Mac and I would like to change the value of an IORegistryEntry. I can view it on the IORegistryExplorer, but I can't edit it. So it's my understanding that I have to edit it via code. Here is my code:

CFMutableDictionaryRef matchingDict = IOServiceNameMatching("AppleUSBMultitouchDriver");
io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
if(service) {
 CFStringRef manufacturer = IORegistryEntryCreateCFProperty(service, CFSTR("Manufacturer"), kCFAllocatorDefault,0);
 NSLog(@"%@", (NSString*)manufacturer);
 kern_return_t err = IORegistryEntrySetCFProperty(service, CFSTR("Manufacturer"), CFSTR("test"));
 NSLog(@"error = %d", err);
}

This will output

2010-04-10 16:09:09.015 Test[41548:a0f] Apple Inc.
2010-04-10 16:09:09.015 Test[41548:a0f] error = 0

But after I check the value in the IORegistryExplorer, it still doesn't change. Does anybody have any suggestions?

Thank you


回答1:


In order for this to be possible, usually the driver for the particular hardware you're changing has to implement setProperties() (in IOKit) that makes this change for you.

It's unlikely that Apple will implement setProperty() in their AppleUSBMultitouchDriver in a way that allows you to change the manufacturer name. They want to specify what kind of fruit they are. ;)




回答2:


Use IOConnectSetCFProperties instead of IORegistryEntrySetCFProperty. Pass it a dictionary with the settings you want to set.

For example to turn off three finger swipe to navigate, call it with a dictionary containing { TrackpadThreeFingerSwipe = 0; }




回答3:


This is example how to change trackpad settings properly. Trackpad.prefpane do exactly this, but also save this setting somewhere in defaults (if you will not find out where exactly, ask here about it).

P.S. getEVSHandle() may be found in MachineSettings.framework.

P.P.S. Checked only on 10.5 & 10.6.

NSInteger zero = 0, one = 1;

CFNumberRef _numberWith0 = CFNumberCreate(kCFAllocatorDefault, kCFNumberNSIntegerType, &zero);
CFNumberRef _numberWith1 = CFNumberCreate(kCFAllocatorDefault, kCFNumberNSIntegerType, &one);

CFMutableDictionaryRef propertyDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, NULL, NULL);

CFDictionarySetValue(propertyDict, @"TrackpadThreeFingerSwipe", flag ? _numberWith1 : _numberWith0);

io_connect_t connect = getEVSHandle();

if (!connect)
{
// error
}

kern_return_t status = IOConnectSetCFProperties(connect, propertyDict);

if (status != KERN_SUCCESS)
{
//error
}

CFRelease(propertyDict);


来源:https://stackoverflow.com/questions/2615039/cant-edit-ioregistryentry

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!