iOS touch event notifications (private API)
You can use the IOHID stuff in IOKit to get the x, y coordinates.
#include <IOHIDEventSystem.h>
create IOHIDEventSystemClient:
void *ioHIDEventSystem = IOHIDEventSystemClientCreate(kCFAllocatorDefault);
register callback:
IOHIDEventSystemClientScheduleWithRunLoop(ioHIDEventSystem, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDEventSystemClientRegisterEventCallback(ioHIDEventSystem, handle_event, NULL, NULL);
unregister callback:
IOHIDEventSystemClientUnregisterEventCallback(ioHIDEventSystem, handle_event, NULL, NULL);
IOHIDEventSystemClientUnscheduleWithRunLoop(ioHIDEventSystem, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
callback:
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) ;
}
}
Also, you can check this out:
IOHIDEventSystemCreate on iOS6 failed.
Hope this helps.
EDIT: Please see the result from the log. Tested on iPhone 4 and 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
}
}
How can I simulate the touch events by IOHIDEvent?
As I mentioned in my answer to your other question today, you might try looking at GSEvent.h
from GraphicsServices.framework, or in IOKit.framework.
Here are some good answers on stackoverflow to help you:
iOS Private API: lock device and power off the screen
GSSendEvent - Inject Touch Event iOS
iOS touch event notifications (private API)
Ideal way to notify ios application about an event from an SDK
I suggest you to use delegate instead of NSNotification :
You probably want only 1 response to your call, so if you need NSNotification, nothing prevent the client app to answer it several times.
If the user need notification, he can implement it himself inside your delegates methods.
Delegates provide instant response, NSNotification is asynchronous. If you need information from client, you should ask for a sync response.
Cheers
Related Topics
What Is Prefix.Pch File in Xcode
Possible to Handle Your Own Http Url Schemes in iOS
Warning: the Copy Bundle Resources Build Phase Contains This Target's Info.Plist File
Uitabbar Items Jumping on Back Navigation on iOS 12.1
How Does Square's Cardcase App Automatically Populate the User's Details from the Address Book
Uicollectionview Decoration View
Uiviewcontentmodescaleaspectfill Not Clipping
Send a File as Attachment in Objective C
Autolayout: Add Constraint to Superview and Not Top Layout Guide
First App Update, User Data Lost (Was Stored in Documents Directory)
Implementing Google Custom Search API in iOS
Xcode 8 "The Aps-Environment Entitlement Is Missing from the App's Signature" on Submit
Xcode 11 Backward Compatibility: "Uiwindowscene Is Only Available in iOS 13 or Newer"
How to Prompt the User to Turn on Location Services After User Has Denied Their Use
iOS - Parse Issues in Nsobjcruntime, Nszone, and Nsobject
How to Get an Iphone's Device Name