NSURLConnection导致错误的访问崩溃

问题描述 投票:4回答:1

在过去的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内部崩溃。

redirect crash nsurlconnection
1个回答
0
投票

这可能有用:Asynchronous NSURLConnection Throws EXC_BAD_ACCESS

例如:

我用NSZombieEnabled标志修复了我的问题。我的问题是提供NSURL是autorelease对象。因此,URL对象在某个特定时间解除分配,并且在内部API代码中访问它失败。

© www.soinside.com 2019 - 2024. All rights reserved.