8

I know that is possible to intercept a tap on a screen, but I want to know if is it possible to simulate a tap in a point of screen (with x and y coordinates). Thanks

Andrea
  • 1,597
  • 3
  • 18
  • 24
  • possible duplicate of [How to simulate touch event ?](http://stackoverflow.com/questions/992299/how-to-simulate-touch-event) – Max Mar 01 '11 at 22:06

2 Answers2

3
UITouch *touch = [[UITouch alloc] initInView:view];
UIEvent *eventDown = [[UIEvent alloc] initWithTouch:touch];

[touch.view touchesBegan:[eventDown allTouches] withEvent:eventDown];

[touch setPhase:UITouchPhaseEnded];
UIEvent *eventUp = [[UIEvent alloc] initWithTouch:touch];

[touch.view touchesEnded:[eventUp allTouches] withEvent:eventUp];

[eventDown release];
[eventUp release];
[touch release];

from here http://cocoawithlove.com/2008/10/synthesizing-touch-event-on-iphone.html

madmik3
  • 6,975
  • 3
  • 38
  • 60
  • 14
    downvote because - this technique is out of context and requires more code (at the link) that uses private API's. – TomSwift Mar 01 '11 at 22:37
  • 5
    upvote because - synthesizing a touch in general is going to require accessing some sort of private API. – Shoerob Jan 13 '12 at 16:23
1

If it is a non-jailbroken device, check this: PTFakeTouch (worked for ios 11). It only works inside your applications. Since you are using private APIs, you might get rejected from the App Store.

If you want to simulate system-wide touch events, you have to jailbreak your device.

Check these links for jailbroken devices:

Simulate Touch Event on iOS - jailbroken - iOS13+

Is possible to simulate touch event using an external keyboard on ios jailbroken?

Jason Z
  • 39
  • 6