NSURLConnection results in bad access failure

I struggled with this for the past 48 hours and searched all the forums unnecessarily. I am using NSURLConnection to asynchronously download a series of web files. It accidentally crashes after downloading several files, the number of which is not fixed.

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 viewing the previous thread in stackoverflow, this is really a problem with the redirect requests being sent. The proposed solution has been implemented

 - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *) redirectResponse { return request; } 

I did it, but anyway the crash there. In addition, the behavior before the failure is that willSendRequest is called twice, and no other delegate methods are called for this request. It crash inside inside NSURLResponse .

+4
source share
1 answer

This may be useful: Asynchronous NSURLConnection throws EXC_BAD_ACCESS

For instance:

I fixed my problem with the NSZombieEnabled flag. My problem was posed. NSURL was the subject of an abstract. Thus, the URL object was released at a specific time and access to it failed in the internal API code.

0
source

Source: https://habr.com/ru/post/1313766/


All Articles