ios:NSURLConnection会定期崩溃

时间:2011-03-28 17:29:08

标签: iphone objective-c nsurlconnection

我有随机EXC_CRASH崩溃,我认为我已将其缩小到NSURLConnection。需要注意的一点是,我在后台选择器中调用以下内容,这可能是个问题吗?

我从以下NSURLConnection方法接收NSData:

NSString *urlStr = [NSString stringWithFormat:@"%@",url];
    NSURL *serviceUrl = [NSURL URLWithString:urlStr];
    NSMutableURLRequest *serviceRequest = [NSMutableURLRequest requestWithURL:serviceUrl];
    [serviceRequest setHTTPMethod:@"GET"];
    [serviceRequest setCachePolicy:NSURLRequestUseProtocolCachePolicy];
    [serviceRequest setTimeoutInterval:30.0];

    NSURLResponse *serviceResponse = nil;
    NSError *serviceError = nil;

    // Get the downloaded data
    NSData *returnedData = [NSURLConnection sendSynchronousRequest:serviceRequest returningResponse:&serviceResponse error:&serviceError];

    // Do stuff with returnedData;

崩溃日志:

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x00011a1c __pthread_kill + 8
1   libsystem_c.dylib               0x000333b4 pthread_kill + 52
2   libsystem_c.dylib               0x0002bbf8 abort + 72
3   libstdc++.6.dylib               0x00044a64 __gnu_cxx::__verbose_terminate_handler() + 376
4   libobjc.A.dylib                 0x0000606c _objc_terminate + 104
5   libstdc++.6.dylib               0x00042e36 __cxxabiv1::__terminate(void (*)()) + 46
6   libstdc++.6.dylib               0x00042e8a std::terminate() + 10
7   libstdc++.6.dylib               0x00042f5a __cxa_throw + 78
8   libobjc.A.dylib                 0x00004c84 objc_exception_throw + 64
9   Foundation                      0x0008f924 __NSThreadPerformPerform + 648
10  CoreFoundation                  0x00075a72 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
11  CoreFoundation                  0x00077758 __CFRunLoopDoSources0 + 376
12  CoreFoundation                  0x000784e4 __CFRunLoopRun + 224
13  CoreFoundation                  0x00008ebc CFRunLoopRunSpecific + 224
14  CoreFoundation                  0x00008dc4 CFRunLoopRunInMode + 52
15  GraphicsServices                0x00004418 GSEventRunModal + 108
16  GraphicsServices                0x000044c4 GSEventRun + 56
17  UIKit                           0x0002ed62 -[UIApplication _run] + 398
18  UIKit                           0x0002c800 UIApplicationMain + 664
19  PUC                             0x0009e7cc 0x1000 + 645068
20  PUC                             0x0009e780 0x1000 + 644992

Thread 1 name:  Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0   libsystem_kernel.dylib          0x00012fbc kevent + 24
1   libdispatch.dylib               0x00006094 _dispatch_mgr_invoke + 672
2   libdispatch.dylib               0x0000704a _dispatch_queue_invoke + 86
3   libdispatch.dylib               0x0000660a _dispatch_worker_thread2 + 190
4   libsystem_c.dylib               0x0003458a _pthread_wqthread + 258
5   libsystem_c.dylib               0x00034bbc start_wqthread + 0

Thread 2 name:  WebThread
Thread 2:
0   libsystem_kernel.dylib          0x0000fc00 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x0000f758 mach_msg + 44
2   CoreFoundation                  0x000762b8 __CFRunLoopServiceMachPort + 88
3   CoreFoundation                  0x00078562 __CFRunLoopRun + 350
4   CoreFoundation                  0x00008ebc CFRunLoopRunSpecific + 224
5   CoreFoundation                  0x00008dc4 CFRunLoopRunInMode + 52
6   WebCore                         0x0000637a RunWebThread(void*) + 378
7   libsystem_c.dylib               0x0003330a _pthread_start + 242
8   libsystem_c.dylib               0x00034bb4 thread_start + 0

Thread 3:
0   libsystem_kernel.dylib          0x0000fc00 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x0000f758 mach_msg + 44
2   CoreFoundation                  0x000762b8 __CFRunLoopServiceMachPort + 88
3   CoreFoundation                  0x00078562 __CFRunLoopRun + 350
4   CoreFoundation                  0x00008ebc CFRunLoopRunSpecific + 224
5   CoreFoundation                  0x00008dc4 CFRunLoopRunInMode + 52
6   Foundation                      0x0002a7f6 +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] + 206
7   Foundation                      0x0001d382 -[NSThread main] + 38
8   Foundation                      0x0008f5c6 __NSThread__main__ + 966
9   libsystem_c.dylib               0x0003330a _pthread_start + 242
10  libsystem_c.dylib               0x00034bb4 thread_start + 0

2 个答案:

答案 0 :(得分:5)

像其他人一样使用ASIHttpRequest。容易。

唯一的选择是重写(绝对没有理由)ASIHttpRequest中的5,000行代码。

这是唯一的解决方案。

答案 1 :(得分:1)

为ASIHTTPRequest +1。另外,既然你已经提到你在后台运行它,请检查你是否在一些视图控制器的dealloc方法中意外释放它。