3

IOHIDEventSystemCreate 在 iOS6 上总是返回 NULL(在 iOS5 上工作正常)。有谁知道为什么?

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;
}
4

2 回答 2

1

是的,它也不适用于我的 iOS6。我现在使用这个:

void *system = IOHIDEventSystemClientCreate(kCFAllocatorDefault);
IOHIDEventSystemClientScheduleWithRunLoop(system, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDEventSystemClientRegisterEventCallback(system, handle_event, NULL, NULL);
CFRunLoopRun();

但我不知道为什么它只报告多点触控+键盘事件。iOS6 中的 SpringBoard 称之为:

IOHIDEventSystemClientSetMatchingMultiple(system, array);

使用包含 PrimaryUsagePage + PrimaryUsage 的数组,但我无法让它工作......例如,如果有人知道获取加速度计事件的解决方案,我也很感兴趣。

于 2013-02-27T17:33:31.460 回答
-1

当您将 IOKit.framework 拖到项目中时,您可以更改诸如 #include "IOHIDEventSystem.h" 之类的标题

于 2018-03-23T15:18:07.023 回答