EHarpham
EHarpham

Reputation: 622

Simulate tap in iOS webview with button

I am trying to build an app for people with disabilities who are unable to use gestures such as swipe and pinch. I realise there is no way to simulate taps inside iOS however is it possible to somehow send a a tap event to a webview so they could control the internet.

Perhaps this can be done with Javascript?

I have looked on this subject for some time but cannot find any answers.

Any help greatly appreciated

Upvotes: 1

Views: 1195

Answers (1)

Jacob Oscarson
Jacob Oscarson

Reputation: 6393

You will need to inject Javascript into the UIWebView (using stringByEvaluatingJavaScriptFromString:). Your Javascript will then need to simulate the events that you want to inject, using document.createElement etc. I think injecting jQuery and plugins is a bit overkill (the UIWebView will always be a modern WebKit for starters), but if you feel inexperienced in web technology that's of course a viable way. A library that's especially targeted to simulating touch events is thumbs.js.

Otherwise, this is the canonical starting point when starting to learn about DOM events.

You'll need to inject your 'agent' code into every URL the UIWebView visits. I've had luck with doing this in webViewDidFinishLoad:.

Upvotes: 1

Related Questions