AFNetworking/AFNetworking — Issue #237: Loading images via file:// URI's causes a crash on ios4
Author: tleyden
Created: 2012-03-08 20:41:18+00:00
State: open

When loading a bundled image from a file:// URI using:

- (void)setImageWithURL:(NSURL *)url
placeholderImage:(UIImage *)placeholderImage

we were seeing the following crash:

Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURLResponse statusCode]: unrecognized selector sent to instance 0x5f9f250'

Last Exception Backtrace:
0 CoreFoundation 0x3545d63d __exceptionPreprocess + 97
1 libobjc.A.dylib 0x314b2c5d objc_exception_throw + 25
2 CoreFoundation 0x354611bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 103
3 CoreFoundation 0x35460649 ___forwarding___ + 509
4 CoreFoundation 0x353d7180 _CF_forwarding_prep_0 + 48
5 Associate 0x000aca9f -[AFHTTPRequestOperation hasAcceptableStatusCode] (AFHTTPRequestOperation.m:81)
6 Associate 0x000ac6c9 -[AFHTTPRequestOperation error] (AFHTTPRequestOperation.m:58)

What was happening is that the NSUrlConnection was returning an NSURLResponse instead of an NSHttpUrlResponse. Since NSURLResponse does not have a statusCode method, it was causing a crash.