3

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;
}
Nate
  • 31,017
  • 13
  • 83
  • 207
Kevin Cao
  • 1,332
  • 1
  • 8
  • 13

2 Answers2

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.

Guigeek
  • 21
  • 4
-1

you can change headers like #include "IOHIDEventSystem.h" when you drag IOKit.framework to your project

vincent
  • 1
  • 1
  • 1
    Actually, please remove this answer. This should be a comment on the other answer. But, this is a 5 year old question, so it's likely not relevant today. – adprocas Mar 23 '18 at 17:29