Catching Unused Transition Events in UIWebView

I am working on an iPad application based on UIWebView: to explain it in the simplest conditions, the application shows one large interactive web view and, in addition, supports user gestures.

I need to catch events that represent individual cranes in a webview, but only when the cranes have not been used by the webview (i.e. they are not the start of the scroll / zoom operation, they are not link cranes, they are not cranes that run some javascript).

UIWebView is very greedy for its events, and, in my experience, it does not distribute them even when they are not consumed. To catch the events, I finished subclassing the main UIWindow (see http://mithin.in/2009/08/26/detecting-taps-and-events-on-uiwebview-the-right-way/ ). This works well, but the problem is that I cannot find out if the taps I get triggered in javascript in webview or not.

As an additional limitation, I cannot control the javascript that will be run in the UIWebView or the HTML that it will be displayed.

So the question will be: what is the way to detect all and only crane events that did not trigger any other actions in the UIWebView itself, especially in javascript actions?

~

If you're interested, the source code for the project I'm working on is on GitHub: to find it, just ask Google to point you to the Baker Framework.

+4
source share
1 answer

Do it using JavaScript. Firstly, after your web interface completes the download, attach the javascript handler to the body to absorb any unused clicks. Do you upload the populated domain as an action:

- (void)webViewDidFinishLoad:(UIWebView *)webView { NSString *script = @"document.body.onclick = function () { document.location.href = 'http://clickhandler'; }" [webView stringByEvaluatingJavaScriptFromString:script]; } 

Then, in your web browsing deed, notice the attempts to load the created domain and intercept them. Now you have a way to intercept the javascript handler using your own code and react accordingly:

 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { if ([request.URL.host isEqualToString:@"clickhandler"]) { //handle click //your logic here return NO; } return YES; } 
+4
source

Source: https://habr.com/ru/post/1334252/


All Articles