I\'m having a random UIWebView
crash using iOS8.1 and UIWebView
, using an iPhone5. In my tests the crash doesn\'t
This work around appears to fix it for my app. I'm not comfortable with this, but it's currently the only thing I've been able to figure out to get rid of the crash.
[self.webView performSelector:@selector(loadRequest:) withObject:urlRequest] afterDelay:0.5];
Or, if you want something safer you can use WKWebView on iOS 8+
Since WKWebView doesn't support local files, start a web server:
[GCDWebServer setLogLevel:4];
webServer = [[[GCDWebServer alloc] init] retain];
[webServer addGETHandlerForBasePath:@"/" directoryPath:rootDir indexFilename:@"index.html" cacheAge:3600 allowRangeRequests:YES];
[webServer startWithPort:0 bonjourName:nil];
Then, depending on the OS version, create your webview:
if (NSClassFromString(@"WKWebView"))
{
NSString* jScript = @"";
WKUserScript* wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
WKUserContentController* wkUController = [[WKUserContentController alloc] init];
[wkUController addUserScript:wkUScript];
WKWebViewConfiguration* wkWebConfig = [[WKWebViewConfiguration alloc] init];
wkWebConfig.userContentController = wkUController;
webViewNew = [[WKWebView alloc] initWithFrame:CGRectMake(0.f, 0.f, 1.f, 1.f) configuration:wkWebConfig];
webViewNew.navigationDelegate = self;
webViewNew.scrollView.bounces = NO;
webViewNew.scrollView.scrollEnabled = NO;
webViewNew.backgroundColor = [UIColor redColor];
webViewNew.opaque = YES;
}
else
{
webViewOld = [[UIWebView alloc] initWithFrame: CGRectMake (0, 0, 1.0f, 1.0f)];
webViewOld.delegate = self;
[[webViewOld scrollView] setBounces: NO];
webViewOld.scrollView.scrollEnabled = NO;
webViewOld.scalesPageToFit = YES;
[webViewOld setBackgroundColor:[UIColor whiteColor]];
[webViewOld setOpaque:NO];
}
And then browse to: [NSString stringWithFormat: "htztp://127.0.0.1:%d", (int)webServer.port] (Ignore the z in the http, stackoverflow won't let me post urls to localhost)
make sure you set the UIWebView delegate to nil in the dealloc method
- (void)dealloc {
[self.webView stopLoading];
self.webView.delegate = nil;
}
I solved the problem. I had the same issue adding a video tag (source was a local mp4 file approx. 18Mb). I could identify the video tag as the crash responsible because html without video doesn't crash. Then i tried to inject two seconds later the video tag via javascript and the app crashed. After a few hours i found this: UIWebView loading html5-Video EXC_BAD_ACCESS crash.
My solution was to extract the video tag injection in a javascript function and call that function on webViewDidFinishLoad.
So, in my controller i have:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[self.webView stringByEvaluatingJavaScriptFromString:@"placeVideoTag();"];
}
While in my index.html i have:
...
<div id="left">
<div id="media-div"></div>
...
and (i added an audio tag too!):
<script>
function placeVideoTag() {
$('#media-div').html('<video id="videoController" width="100%" controls > <source src="video_1.mp4" type="video/mp4"></video>');
$('#media-div').append('<br/><audio id="audioController" controls="" width="100%"><source src="audio_1.mp3" type="audio/mp3"></audio>');
}
</script>
I know it sounds as a strange solution, but it is really working. I had the same identical issue as stated here, also enabling Zombie tracking
Randomly the app is crashing on the WebThread with EXC_ARM_BREAKPOINT
After enabling Zombie tracking on the console there is this message:
[UIViewAnimationState release]: message sent to deallocated instance 0x14deff70
Try to update to iOS 8.4.1. It worked for us (however, we didn't find any references to this bug in release notes).
I'm experiencing the same issue on iOS 8 and more specifically an iPad 3 fails much more often than others.
Based on your post and a couple of others that I was able to find, it seems that it's an issue with UIWebView
on iOS8 only, as it works on iOS7.
What I've done is to use the new WKWebView
on iOS8, which doesn't present the same issue, while continuing to use UIWebView
on iOS7.
The best thing to do would be to file a radar with Apple and switch to WKWebView
in the meantime.
If you are not using animations you can avoid this bug by disabling Animations. Put this in your controller init method:
[UIView setAnimationsEnabled:NO];