Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

touch event not working in WkWebView

want to handle touch event in wkwebview, tried overriding touchesBegan and adding UITapGestureListener, still couldn't receive touch event call back.

iOS 10.1.1

Posted on Dec 14, 2016 2:14 AM

Reply
1 reply

May 5, 2017 6:37 AM in response to anuruddh1008

I had this question too, but couldn't find a straightforward answer as to why overriding touchesBegan and UIGestureListeners doesn't work on wkwebviews (If anyone knows why, please let me know).


I did some research and came up with 2 workarounds.


First workaround: look at this, this may help you.

http://stackoverflow.com/a/36287135

Personally, I don't like this method because it seems like a lot of work.


Second workaround:

Do some javascript injection. This worked for me.

Go here and scroll down a little.

https://forums.asp.net/t/1899214.aspx?If+no+activity+for+15+minutes+display+an+a lert+on+web+page+and+then+either+continue+or+logout

I injected a modified version of jprochazka's code into my wkwebview.

https://www.youtube.com/watch?v=53Q7mhkES7c

I watched this video and learned how to listen for JavaScript events (like a scroll or a click on the webpage).

So I modified the JavaScript to trigger one of my Swift functions.

Ta da! The workaround is complete.


Hope this helps!

touch event not working in WkWebView

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.