UIWebView loading html5-Video EXC_BAD_ACCESS crash

℡╲_俬逩灬. 提交于 2019-12-03 13:34:49

There is a little trick to override this crash. If you slightly scroll the webview just before the video content is loaded, the crash can be avoided. Before trying it out from code, try scrolling the webView a bit on device with your finger. It won't crash now.

In code, do something like this:

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
  [webView stringByEvaluatingJavaScriptFromString:@"window.scrollTo(0, 10);"];
}

to simulate a scroll on the webview through javascript. The scroll value can be as low as 1, so the user won't notice the scroll at all.

Telling the webview to evaluate any JavaScript (or none at all) on webViewDidFinishLoad: seems work (albeit hacky).

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
  [webView stringByEvaluatingJavaScriptFromString:@""];
}

Seems I've solved this issue... i've moved all HTML-5 video tags insertion in Javascript

function placeVideoTag() {
   var val = '<video />';
   var el = document.getElementById('video-id');
   el.innerHTML = val;
}

And i'm calling JS in [UIWebView didFinishLoad]

- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
   [aWebView stringByEvaluatingJavaScriptFromString:@"placeVideoTag()"];
}

Works perfectly in my case. Other suggestions didn't work for me.

I have exactly the same problem. no answer yet. Saw many others reports similar problems - iOS 4.2.1 only.

Basically, I have a UIView Controller with a webview as its subview, and load a URLRequest to a youtube link.

The first time I load the viewController, the console logs error "Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/System/Library/Internet Plug-Ins/QuickTime Plugin.webplugin/QuickTime Plugin (file not found).". I stop loading and release the viewController. The second time I re-load new viewController with the same request to that youtube link, now the app crashed with EXC_BAD_ACCESS

Thanks, for your posts!!! In my case it only works with different quite high offset-values for Portrait- and Landscape-Mode on iPad

(Portrait-Mode: greater than 60; Landscape-Mode: greater than 780):

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    if (self.interfaceOrientation == UIInterfaceOrientationPortrait ||
    self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {

        [webView stringByEvaluatingJavaScriptFromString:@"window.scrollTo(0, 60);"];
    } else if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
           self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {

        [webView stringByEvaluatingJavaScriptFromString:@"window.scrollTo(0, 780);"];
    }
    webView.loadCounter--;
}

But with this solution my app crashes by double-tapping to zoom during the loading-process of a site.

I did subclass UIWebView to solve this problem (to prevent webView from zooming while loading):

.m:

@synthesize loadCounter;

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    CGPoint p = currentPoint;
    NSTimeInterval t = currentTimestamp;
    currentPoint = point;
    currentTimestamp = [event timestamp];

    if (CGPointEqualToPoint(p, point) &&
        [event timestamp] - t < 0.2 && loadCounter > 0){
        return self.superview;
    }

    return [super hitTest:point withEvent:event];
}

.h:

@interface NonDoubleTapableWhileLoadingWebView : UIWebView {
    CGPoint currentPoint;
    NSTimeInterval currentTimestamp;

    NSInteger loadCounter;
}

@property (assign) NSInteger loadCounter;

And added a counter to determine the last "didFinish"-call and to reactivate the double-tapping possibility (init loadCounter with 0)

- (void)webViewDidStartLoad:(UIWebView *)webView {
    linkWebView.loadCounter++;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!