我对UIWebview
有疑问。当我使用URL加载数据内容时,应用程序已崩溃。它发生在一个月的某个时间。我对它很累,我无法再出现它。它发生在客户端的设备上。请帮我。该应用程序在ios7.1上运行
- 异常类型:EXC_BAD_ACCESS(SIGSEGV)
- 例外子类型:KERN_INVALID_ADDRESS"
- 主题2名称:WebThread
- 线程2崩溃:0 WebCore 0x38322b02 WebCore的:: CachedResource :: unregisterHandle(WebCore的:: CachedResourceHandleBase *) + 110 1 WebCore 0x38322a8a WebCore :: CachedResourceHandleBase :: ~CachedResourceHandleBase()+ 14 2 WebCore 0x384b77fe WebCore :: MemoryCache :: pruneDeadResourcesToSize(unsigned int)+ 278 3 WebCore 0x38396aee WebCore :: MemoryCache :: prune()+ 94"
醇>
以下是我们的源代码。
if ([defaults boolForKey:@"cacheEnabled"]) {
[[NSURLCache sharedURLCache] setMemoryCapacity:[defaults integerForKey:@"cacheSize"]];
} else {
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
}
NSURL *url = [NSURL URLWithString:[defaults objectForKey:@"connectionURL"]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
if ([data length] > 0 && error == nil) [self.webView loadRequest:request];
else if (error != nil) NSLog(@"Error: %@", error);
}];
在dealloc方法中:
[_webView setDelegate:nil];
[_webView stopLoading];
感谢先进!
答案 0 :(得分:0)
我认为您正在加载webview请求的主要问题不在主线程中。
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
if ([data length] > 0 && error == nil) [self.webView loadRequest:request];
else if (error != nil) NSLog(@"Error: %@", error);
}];
1 /您应该将参数队列更改为[NSOperationQueue mainQueue]
2 /其他错误(与崩溃无关):您应该在加载webview之前检查response.statuscode == 200
:D