问题
IOHIDEventSystemCreate always return NULL on iOS6 (work fine on iOS5). Anyone know why?
Example on iPhoneDevWiki
#include <IOKit/hid/IOHIDEventSystem.h>
#include <stdio.h>
void handle_event (void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) {
// handle the events here.
printf("Received event of type %2d from service %p.\n", IOHIDEventGetType(event), service);
}
int main () {
// Create and open an event system.
IOHIDEventSystemRef system = IOHIDEventSystemCreate(NULL);
IOHIDEventSystemOpen(system, handle_event, NULL, NULL, NULL);
printf("HID Event system should now be running. Hit enter to quit any time.\n");
getchar();
IOHIDEventSystemClose(system, NULL);
CFRelease(system);
return 0;
}
回答1:
Yes, it doesn't work on iOS6 for me too. I now use this:
void *system = IOHIDEventSystemClientCreate(kCFAllocatorDefault);
IOHIDEventSystemClientScheduleWithRunLoop(system, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDEventSystemClientRegisterEventCallback(system, handle_event, NULL, NULL);
CFRunLoopRun();
But I don't know why it only reports multitouch+keyboard events. SpringBoard in iOS6 calls this:
IOHIDEventSystemClientSetMatchingMultiple(system, array);
with an array containing PrimaryUsagePage + PrimaryUsage, but I can't get it working... If someone knows a solution for getting accelerometer events for example, I'm interested too.
回答2:
you can change headers like #include "IOHIDEventSystem.h" when you drag IOKit.framework to your project
来源:https://stackoverflow.com/questions/14354240/iohideventsystemcreate-on-ios6-failed