AFDownloadRequestOperation在404响应时崩溃

时间:2014-08-22 22:15:44

标签: ios objective-c afnetworking-2

我在xcode中创建了一个新项目,只有这个代码来测试

NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    cachePath = [cachePath stringByAppendingPathComponent:@"blabla.jpg"];

NSString *fileURL = @"http://en.wikipedia.org/dcjhbdkcjc";

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:fileURL]];
AFDownloadRequestOperation *operation = [[AFDownloadRequestOperation alloc] initWithRequest:request targetPath:cachePath shouldResume:YES];

//AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"%@",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"%@",error);
}];
[operation start];

当使用以下错误控制台返回404时崩溃,测试代码中的NSLog都没有被调用。

2014-08-22 16:51:33.809 AFDownloadTest[7106:3403] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[3]'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000101b39495 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010172d99e objc_exception_throw + 43
    2   CoreFoundation                      0x0000000101b02dce -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 382
    3   CoreFoundation                      0x0000000101b2e23f +[NSDictionary dictionaryWithObjects:forKeys:count:] + 63
    4   AFDownloadTest                      0x000000010002a955 -[AFHTTPResponseSerializer validateResponse:data:error:] + 1893
    5   AFDownloadTest                      0x0000000100002cf2 -[AFDownloadRequestOperation connection:didReceiveData:] + 178
    6   Foundation                          0x000000010141e36b __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 48
    7   Foundation                          0x00000001012d1bdb -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 210
    8   Foundation                          0x00000001012d1aec -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 69
    9   Foundation                          0x00000001012d1e37 _NSURLConnectionDidReceiveData + 79
    10  CFNetwork                           0x0000000106ae8e05 ___ZN27URLConnectionClient_Classic23_delegate_cacheTrifectaEPK20_CFCachedURLResponseU13block_pointerFvvE_block_invoke + 778
    11  CFNetwork                           0x0000000106ae4802 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 84
    12  CoreFoundation                      0x0000000101adff74 CFArrayApplyFunction + 68
    13  CFNetwork                           0x0000000106a573e7 _ZN19RunloopBlockContext7performEv + 133
    14  CFNetwork                           0x0000000106a57217 _ZN17MultiplexerSource7performEv + 247
    15  CFNetwork                           0x0000000106a5703a _ZN17MultiplexerSource8_performEPv + 72
    16  CoreFoundation                      0x0000000101ac8d21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    17  CoreFoundation                      0x0000000101ac85f2 __CFRunLoopDoSources0 + 242
    18  CoreFoundation                      0x0000000101ae446f __CFRunLoopRun + 767
    19  CoreFoundation                      0x0000000101ae3d83 CFRunLoopRunSpecific + 467
    20  Foundation                          0x0000000101339fce -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 253
    21  Foundation                          0x00000001012dfdc0 -[NSRunLoop(NSRunLoop) run] + 74
    22  AFDownloadTest                      0x0000000100011fe8 +[AFURLConnectionOperation networkRequestThreadEntryPoint:] + 280
    23  Foundation                          0x00000001013352df __NSThread__main__ + 1167
    24  libsystem_pthread.dylib             0x000000010236e2fc _pthread_body + 131
    25  libsystem_pthread.dylib             0x000000010236e279 _pthread_body + 0
    26  libsystem_pthread.dylib             0x000000010236c4b1 thread_start + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

暂停应用程序AFURLConnectionOperation.m文件的第169行 这是[runLoop run];

1 个答案:

答案 0 :(得分:0)

这是AFDownloadRequestOperation代码上的一个错误,已于2014年9月4日在此提交a36bd98208上修复