Inject system wide touch events on iOS7
Prior to iOS7 it was possible to inject touch events with the GSSendSystemEvent
and GSSendEvent
private API calls, eg:
- GSSendEvent - Inject Touch Event iOS
- Simulating System Wide Touch Events on iOS
- System-wide tap simulation on iOS
- Send a global touch event on iOS 6
On iOS7 these calls seem to silently fail though. An alternative has been suggested in Simulating system-wide touches in iOS 7 but it only works on jailbroken devices. https://github.com/kif-framework/KIF looks like another option, but it appears that it only supports injecting events for the current app rather than system wide (so you couldn't inject a touch event while you're app is in the background, for example).
So how can you inject system wide touch events on iOS7, without a jailbreak?
Solution 1:
I assume you need to do this system-wide for a testing scenario? In which case you might be well served by Apple's UI Automation framework, a JavaScript-based tool useful for on-device testing.
While you can't do things like simulate a home-button press, you can send your app to the background for a specified duration, for example:
UIATarget.localTarget().deactivateAppForDuration(seconds);
Here are the docs:
https://developer.apple.com/library/ios/documentation/DeveloperTools/Reference/UIAutomationRef