2

I using touchend event in UIWebView follows:

window.ontouchend=function(touchEvent)
{
   ...
}

I use it to track the scroll inside UIWebView and this event normally work in iOS 5+, but this event does not work in iOS 4! How I can track touchend event in javascript in iOS 4?

Thank you in advance for your help.

Stas Telnov
  • 305
  • 2
  • 13

1 Answers1

1

I dont found a way to get to work this JS code in iOS 4 So I decided to leave this code for iOS 5, but for earlier iOS versions I took the decision from this question: How to intercept touches events on a MKMapView or UIWebView objects?

And in my viewController I write this code:

NSString *sysVersion=[[UIDevice currentDevice] systemVersion];
NSArray *sysVersionParse=[sysVersion componentsSeparatedByString:@"."];
int versionNum=[[sysVersionParse objectAtIndex:0] intValue]; //detect ios version
if (versionNum<5)
{
    WildcardGestureRecognizer * tapInterceptor = [[WildcardGestureRecognizer alloc] init];
    tapInterceptor.touchesEndCallback = ^(NSSet * touches, UIEvent * event)
    {
        NSString *jsString = [[NSString alloc] initWithFormat:@"window.ontouchend();"];
        [webview stringByEvaluatingJavaScriptFromString:jsString];
    };
    //and similarly for the other touch actions
    [webview addGestureRecognizer:tapInterceptor];
}

I hope someone is handy!

Community
  • 1
  • 1
Stas Telnov
  • 305
  • 2
  • 13