2

I want to receive x, y coordinates of a touch. I've tried this solution, but it doesn't seem to work for IOS 7. I get the following error:

Tweak.xm:96:2: error: no matching function for call to 'IOHIDEventSystemClientScheduleWithRunLoop' IOHIDEventSystemClientScheduleWithRunLoop(ioHIDEventSystem, CFRu... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/agiera/theosprojects/phoneit/theos/include/IOKit/hid/IOHIDEventSystemClient.h:72:7: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'IOHIDEventSystemClientRef' (aka '__IOHIDEventSystemClient *') void IOHIDEventSystemClientScheduleWithRunLoop(IOHIDEventSystemC... ^ Tweak.xm:97:2: error: no matching function for call to 'IOHIDEventSystemClientRegisterEventCallback' IOHIDEventSystemClientRegisterEventCallback(ioHIDEventSystem, ha... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/agiera/theosprojects/phoneit/theos/include/IOKit/hid/IOHIDEventSystemClient.h:68:7: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'IOHIDEventSystemClientRef' (aka '__IOHIDEventSystemClient *') void IOHIDEventSystemClientRegisterEventCallback(IOHIDEventSyste... ^ 2 errors generated.

Is there an updated implementation or another means to get this functionality for IOS 7?


edit:

code:

#include <IOKit/hid/IOHIDEventSystem.h>
#include <IOKit/hid/IOHIDEventSystemClient.h>
#include <stdio.h>
//Touch Events
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);
    }
}

static void initTouchEventHandling() {
    void *ioHIDEventSystem = IOHIDEventSystemClientCreate(kCFAllocatorDefault);

    IOHIDEventSystemClientScheduleWithRunLoop(ioHIDEventSystem, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
    IOHIDEventSystemClientRegisterEventCallback(ioHIDEventSystem, handle_event, NULL, NULL);
    IOHIDEventSystemClientUnregisterEventCallback(ioHIDEventSystem, handle_event, NULL, NULL);
    IOHIDEventSystemClientUnscheduleWithRunLoop(ioHIDEventSystem, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
}

initTouchEventHandling is called in my constructor. I added IOKit to my private frame works and implemented this fix.


edit2:

I think there is something wrong with the way I am adding the IOKit framework. I tried swapping it for an older version and got the same errors. Then I tried deleting it altogether and got the same errors. Maybe someone can correct something in my makefile:

ARCHS = armv7 arm64
TARGET = iphone:clang:latest:7.0

export THEOS_DEVICE_IP = 192.168.1.104

include theos/makefiles/common.mk

TWEAK_NAME = phoneit
phoneit_FILES = Tweak.xm
phoneit_FRAMEWORKS = UIKit QuartzCore
phoneit_PRIVATE_FRAMEWORKS = IOKit

include $(THEOS_MAKE_PATH)/tweak.mk

after-install::
    install.exec "killall -9 SpringBoard"
SUBPROJECTS += prefs
include $(THEOS_MAKE_PATH)/aggregate.mk
Community
  • 1
  • 1
  • Can you post the code on how you are getting the coordinates. http://stackoverflow.com/a/15633639/334091 check this too – Tamil Aug 26 '14 at 06:17
  • I got the same error using that. Do you think replacing my iokit with an xcode 4 version might fix this? There are know issues with the iokit from xcode 5, but not to specific to mine. – user2089636 Aug 26 '14 at 16:42

2 Answers2

0

You can write your code like this in initTouchEventHandling() :

static void initTouchEventHandling() {

    IOHIDEventSystemClientRef ioHIDEventSystem = IOHIDEventSystemClientCreate(kCFAllocatorDefault);

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

    //add other custom code...
}

This method works for me. Hope this will help you.

sakura
  • 2,249
  • 2
  • 26
  • 39
  • Would you post an example makefile and imports? And maybe also your source of header files? My compiler doesn't recognize those classes. – user2089636 Dec 14 '14 at 04:53
-1

You have two ways to get the user touch location:

1- Using touchesBegan method:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
  UITouch *touch = [touches anyObject];

  // Get the specific point that was touched
  CGPoint point = [touch locationInView:self.view]; 
  NSLog(@"X location: %f", point.x);
  NSLog(@"Y Location: %f",point.y);

}

2- Using UITapGestureRecognizer:

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(userTapped:)];
[tapRecognizer setNumberOfTapsRequired:1];
[tapRecognizer setDelegate:self];
[self.view addGestureRecognizer:tapRecognizer];
Mutawe
  • 6,464
  • 3
  • 47
  • 90
  • Thanks for your code. I should have been more clear though. I'm making a cydiasubstrate tweak and I wanted to get touch location from anywhere including lockscreen and keyboard. I there a system image view I could attach the gesture recognizer to or a class I could hook the touchesBegan method into that wouldn't mess things up? Thanks – user2089636 Aug 26 '14 at 15:57