Send touch events programmatically

We are using the Speech framework to enable users to interact with our app via voice commands. When a user says "start test" we send

DispatchQueue.main.async {
    self.startButton.sendActions(for: .touchUpInside)
}

This works beautifully, except that the screen goes into auto lockout in the middle of a test. Apparently, using sendActions does not actually send a touch event to the OS.

My question is how can I tell the OS that a touch event happened programmatically?

Thank you

There is no way to generate a touch that will trigger what you want it to (e.g. inform the system that the user is actively using the device) because that information is held entirely outside of your process.

The closest thing you can do is use UIApplication.idleTimerDisabled, although I think there is still a system overall limit on how long that will operate for.

I'm not entirely certain what you mean by testing in this context, but if this is really just for testing your application (this isn't something an end user would use) then you may want to look into UIAutomation and XCUITest instead.

Thank you for your reply. The app allows the user to test another individual, so my mention of testing did not refer to code testing. Sorry for the confusion.

It's sad that we cannot use voice commands after all, since we cannot actually "tap" a button (as far as the OS's idle timer is concerned) without physically touching it. I hope that changes someday.

Send touch events programmatically
 
 
Q