过去48小时我一直在与此作斗争并且搜索所有论坛毫无用处。
我正在使用NSURLConnection
异步下载一系列Web文件。下载几个文件后,它会随机崩溃,其数量不固定。
请参阅下面的调用堆栈:
#0 0x35b634f4 in objc_msgSend
#1 0x3527c2ca in CFEqual
#2 0x3532e750 in __CFBasicHashStandardEquateKeys
#3 0x35330514 in ___CFBasicHashFindBucket_Linear
#4 0x3527c07c in CFBasicHashFindBucket
#5 0x3527bf5c in CFDictionaryGetValue
#6 0x31d15cb4 in HTTPMessage::copyConstantHeaderFieldValue
#7 0x31d6526c in URLRequest::copyConstantHeaderFieldValue
#8 0x31d606f8 in HTTPProtocol::getCacheStoragePolicy
#9 0x31d62cd0 in HTTPProtocol::updateForHeader
#10 0x31d64524 in HTTPProtocol::performHeaderRead
#11 0x31d64bf8 in HTTPProtocol::httpReadStreamEvent
#12 0x352c4302 in _signalEventSync
#13 0x352c427c in _cfstream_shared_signalEventSync
#14 0x352ed294 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
#15 0x352ef0e2 in __CFRunLoopDoSources0
#16 0x352f0058 in __CFRunLoopRun
#17 0x352970c2 in CFRunLoopRunSpecific
#18 0x35296fd0 in CFRunLoopRunInMode
#19 0x30a1f31c in +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:]
#20 0x309ef618 in -[NSThread main]
#21 0x30a75146 in __NSThread__main__
在stackoverflow上看到此前一个线程后,发送重定向请求确实存在问题。解决方案建议实施
- (NSURLRequest *)connection:(NSURLConnection *)connection
willSendRequest:(NSURLRequest *)request
redirectResponse:(NSURLResponse *) redirectResponse
{
return request;
}
我做到了但仍然崩溃了。
崩溃之前的行为也是,willSendRequest
被调用两次,并且没有为此请求调用其他委托方法。它在NSURLResponse
内部崩溃。
答案 0 :(得分:0)
这可能有用: Asynchronous NSURLConnection Throws EXC_BAD_ACCESS
例如:
我用NSZombieEnabled标志修复了我的问题。我的问题是提供NSURL是autorelease对象。因此,URL对象在某个特定时间解除分配,并且在内部API代码中访问它失败。