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)