NSURLConnection导致访问崩溃 [英] NSURLConnection causes bad access crash
问题描述
我一直在争取过去48小时,搜索所有论坛,没有使用。
我使用 NSURLConnection
异步下载一系列的网络文件。
请参阅下面的调用堆栈:
#0 0x35b634f4在objc_msgSend
pre>
#1 0x3527c2ca在CFEqual
#2 0x3532e750在__CFBasicHashStandardEquateKeys
#3 0x35330514在___CFBasicHashFindBucket_Linear
# 4 0x3527c07c在CFBasicHashFindBucket
#5 0x3527bf5c在CFDictionaryGetValue
#6 0x31d15cb4在HTTPMessage :: copyConstantHeaderFieldValue
#7 0x31d6526c在URLRequest :: copyConstantHeaderFieldValue
#8 0x31d606f8在HTTPProtocol :: getCacheStoragePolicy
#9 0x31d62cd0 in HTTPProtocol :: updateForHeader
#10 0x31d64524 in HTTPProtocol :: performHeaderRead
#11 0x31d64bf8 in HTTPProtocol :: httpReadStreamEvent
#12 0x352c4302 in _signalEventSync
#13 0x352c427c在_cfstream_shared_signalEventSync
#14 0x352ed294在__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
在__CFRunLoopDoSources0
## 15 0x352ef0e2 16 0x352f0058在__CFRunLoopRun
#17 0x352970c2在CFRunLoopRunSpecific
#18 0x35296fd0在CFRunLoopRunInMode
#19 0x30a1f31c in + [NSURLConnection(NSURLConnectionReallyInternal)_resourceLoadLoop:]
#20 0x309ef618 in - [NSThread main]
#21 0x30a75146 in __NSThread__main__
在stackoverflow上看到上一个线程后,确实是发送重定向请求的问题。解决方案建议实现
- (NSURLRequest *)连接:(NSURLConnection *)连接
willSendRequest NSURLRequest *)request
redirectResponse:(NSURLResponse *)redirectResponse
{
return request;
}
我这样做,但仍然崩溃。
崩溃之前的行为是,willSendRequest
被调用两次,并且没有其他委托方法被调用这个请求。它会在NSURLResponse
内部崩溃。解决方案$ b 异步NSURLConnection Throws EXC_BAD_ACCESS
例如:
我修复了NSZombieEnabled标志的问题。我的问题是提供的NSURL是autorelease对象。因此,URL对象在某个特定时间被释放,并且在内部API代码中访问失败。
I have been fighting with this for the past 48 hours and searching all forums with no use. I am using
NSURLConnection
to asynchronously download a series of web files. It randomly crashes after downloading a few files, the number of which is not fixed.Please see the call stack below:
#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__
After seeing a previous thread on this on stackoverflow it is indeed a problem with redirect requests being sent. The solution suggested there was to implement
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *) redirectResponse { return request; }
I did that but still the crash is there. Also the behaviour before crash is that,
willSendRequest
is being called twice and no other delegate method is called for this request. It crashes internally inNSURLResponse
.解决方案This may helpful: Asynchronous NSURLConnection Throws EXC_BAD_ACCESS
For example:
I've fixed my problem with NSZombieEnabled flag. My problem was supplied NSURL was autorelease object. So the URL object deallocated at some specific time, and accessing to it failed in internal API code.
这篇关于NSURLConnection导致访问崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!