iOS 触摸事件通知(私有(private) API)

标签 ios jailbreak iphone-privateapi

有可能simulate touch events on iOS ,并且您可以在后台使用 CTTelephonyCenterAddObserver 和 CFNotificationCenterAddObserver 接收各种系统范围的通知,例如:

不过,我还没有找到在后台获取触摸通知的方法。是否有可以与 CFNotificationCenterAddObserver 一起使用的“触摸事件”,可以使用不同的通知中心,或者完全不同的方法?

我对低级触摸信息(例如 x、y 坐标和触摸类型)很满意,但更高级别的信息(例如按键按下、后退按钮按下等)会更好!

最佳答案

您可以使用 IOKit 中的 IOHID 内容来获取 x、y 坐标。

#include <IOHIDEventSystem.h>

创建 IOHIDEventSystemClient:

void *ioHIDEventSystem = IOHIDEventSystemClientCreate(kCFAllocatorDefault);

注册回调:

IOHIDEventSystemClientScheduleWithRunLoop(ioHIDEventSystem, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDEventSystemClientRegisterEventCallback(ioHIDEventSystem, handle_event, NULL, NULL);

注销回调:

IOHIDEventSystemClientUnregisterEventCallback(ioHIDEventSystem, handle_event, NULL, NULL);
IOHIDEventSystemClientUnscheduleWithRunLoop(ioHIDEventSystem, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);

回调:

void handle_event (void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) {
   if (IOHIDEventGetType(event)==kIOHIDEventTypeDigitizer){
       IOHIDFloat x=IOHIDEventGetFloatValue(event, (IOHIDEventField)kIOHIDEventFieldDigitizerX);
       IOHIDFloat y=IOHIDEventGetFloatValue(event, (IOHIDEventField)kIOHIDEventFieldDigitizerY);
       int width = [[UIScreen mainScreen] bounds].size.width;
       int height = [[UIScreen mainScreen] bounds].size.height;
       NSLog(@"click : %f, %f", x*width, y*height) ;
   }
}

此外,您还可以查看以下内容: IOHIDEventSystemCreate on iOS6 failed . 希望这会有所帮助。

编辑:请查看日志中的结果。在 iPhone 4 和 5 上测试。

void handle_event (void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) {
    NSLog(@"handle_event : %d", IOHIDEventGetType(event));
if (IOHIDEventGetType(event)==kIOHIDEventTypeDigitizer){
    IOHIDFloat x=IOHIDEventGetFloatValue(event, (IOHIDEventField)kIOHIDEventFieldDigitizerX);
    IOHIDFloat y=IOHIDEventGetFloatValue(event, (IOHIDEventField)kIOHIDEventFieldDigitizerY);
    NSLog(@" x %f : y %f", x, y);
//2013-03-28 10:02:52.169 MyIOKit[143:907] handle_event : 11
//2013-03-28 10:02:52.182 MyIOKit[143:907]  x 0.766754 : y 0.555023
}
}

关于iOS 触摸事件通知(私有(private) API),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15537564/

相关文章:

ios - 如何在 Objective-C 中定义 API Url

ios - 使用第 3 方库将二进制文件提交给 Apple

iphone - UIActivityIndi​​catorView 卡住

iphone - 无法使用 ios 6.1.2 在 iphone4 上卸载 com.apple.CommCenter.plist?

ios - 即使应用程序在后台运行,如何在越狱 ios 设备上收听所有触摸事件

ios - 椰子足 : target has transitive dependencies that include static binaries when installing 'VialerSIPLib'

jailbreak - 如何以编程方式解锁 iOS 屏幕?

ios - 如何在 iOS 上通过 bundle id 打开应用程序

ios - "The app references non-public selectors in Payload"

objective-c - 在后台接收蓝牙管理器通知