IOHIDEventSystemCreate 在 iOS6 上总是返回 NULL(在 iOS5 上工作正常)。 有人知道为什么吗?
#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;
}
最佳答案
是的,它也不适用于我的 iOS6。 我现在用这个:
void *system = IOHIDEventSystemClientCreate(kCFAllocatorDefault);
IOHIDEventSystemClientScheduleWithRunLoop(system, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDEventSystemClientRegisterEventCallback(system, handle_event, NULL, NULL);
CFRunLoopRun();
但是我不知道为什么它只报告多点触控+键盘事件。 iOS6 中的 SpringBoard 调用这个:
IOHIDEventSystemClientSetMatchingMultiple(system, array);
有一个包含 PrimaryUsagePage + PrimaryUsage 的数组,但我无法让它工作... 例如,如果有人知道获取加速度计事件的解决方案,我也很感兴趣。
关于iphone - iOS6 上的 IOHIDEventSystemCreate 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14354240/