IOHIDEventSystemCreate on iOS6 failed

☆樱花仙子☆ 提交于 2019-12-30 07:17:09

问题


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

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