-->

Simulating System Wide Touch Events on iOS

2019-01-23 09:47发布

问题:

I need to programmatically add touch events to iOS devices system wide without using a jailbreak; how do I do this?

Preferably I'd like to use a private API to do this running in an app in the background. I am aware that doing this prevents my app's availability on the app store; this is however a private app so it isn't a problem.

回答1:

What you need to do is first create the events you want, and then send them to SpringBoard over the "purple port" eg. mach port. To make them system wide you must forward them to each application over the port. That means you need to actually do what the windowmanager does and looking at which app is active, screen locked, etc.

There are a hand full of private framework APIs that work (IOSurface, GraphicServices, SpringBoardServices, etc.) to get you the pieces you need.

You will have to load these private frameworks at runtime using something like dlopen().

This is 100% possible without jailbreak as of iOS 6.1.4 (current ATM), but you will be loading private frameworks which is not allowed by apple for AppStore ;)



回答2:

It is possible. Exactly how you mentioned, using GSEvents and sending them to the purple named port of the aplication you are trying to control/simulate. Of course you need KennyTM's GSEvent.h to accomplish this. I've done this for iOS 4.3, just by changing some of the values that Kenny had (like kGSHandInfoTypeTouchDown), but now I'm trying to do it for iOS 5 and it's not working, till now.

EDIT: It is now working for iOS 5.1.



回答3:

Without jailbreaking there is no real way to hook a gesture recognizer into all views of the entire system. First off, your app running in the background doesn't have the ability of executing this code.