tl;dr- How can I programmatically perform a native touch in specific point on the screen?
Within the web view there is HTML that contains an Iframe, so the web view code and elements are not accessible and sanding massages to JS is not possible either. There is a button in the web view on specific coordinates. How can I press it programmatically?
If you don't want to simulate the touch on the JavaScript level, you can use this extension on UITouch
and UIEvent
, just bridge it to Swift:
func performTouchInView(view: UIView) { let touch = UITouch(inView: view) let eventDown = UIEvent(touch: touch) touch.view!.touchesBegan(eventDown.allTouches()!, withEvent: eventDown) touch.setPhase(.Ended) let eventUp = UIEvent(touch: touch) touch.view!.touchesEnded(eventUp.allTouches()!, withEvent: eventUp) }
Your syntax may vary depending on the version of Swift you use. I'm doing some forced-unwrapping here but you should get the general idea of what is happening.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With