Iphone NSURL连接崩溃

Iphone NSURL连接崩溃,iphone,iphone-sdk-3.0,nsurlconnection,Iphone,Iphone Sdk 3.0,Nsurlconnection,我通过创建一个NSO操作并同步打开NSURLConnections来实现服务器的后端数据加载 这段代码在模拟器和设备中都工作得很好,直到我添加了一个进度条,通知返回到主线程 - (void)start { // stop execution if it's cancelled if([self isCancelled]) { [self willChangeValueForKey:@"isFinished"]; finished =

我通过创建一个NSO操作并同步打开NSURLConnections来实现服务器的后端数据加载

这段代码在模拟器和设备中都工作得很好,直到我添加了一个进度条,通知返回到主线程

- (void)start {
     // stop execution if it's cancelled

     if([self isCancelled]) {
          [self willChangeValueForKey:@"isFinished"];
          finished = YES;
          [self didChangeValueForKey:@"isFinished"];
          return;
     } 

     // If the operation is not canceled, begin executing the task.
     [self willChangeValueForKey:@"isExecuting"];
     [NSThread detachNewThreadSelector:@selector(main ) toTarget:selfwithObject:nil];
     executing = YES;
     [self didChangeValueForKey:@"isExecuting"];
}
现在我在同步调用中遇到EXC_BAD_访问崩溃

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/index.php", rootURL]];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[bodyString dataUsingEncoding:NSUTF8StringEncoding]];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];

NSError *error = nil;
NSURLResponse *response = nil;
receivedData = [[NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error] mutableCopy];
stacktrace的运行方式如下:

#0  0x3430debc in objc_msgSend ()
#1  0x3136f996 in NSPopAutoreleasePool ()
#2  0x31374160 in -[NSAutoreleasePool release] ()
#3  0x331a0408 in _UIApplicationHandleEvent ()
#4  0x325339c4 in PurpleEventCallback ()
#5  0x3147a52a in CFRunLoopRunSpecific ()
#6  0x31479c1e in CFRunLoopRunInMode ()
#7  0x3314ec08 in -[UIApplication _run] ()
#8  0x3314d230 in UIApplicationMain ()
#9  0x00002ab0 in main (argc=1, argv=0x2ffff504)
启用NSZombie后,我可以

*** -[NSDateComponents release]: message sent to deallocated instance 0x172fd0
我知道正在建立连接(查看服务器日志,请求正在通过)。NSURLConnection之前,NSOperation代码中的任何位置都没有分配NSDateComponent对象

我一直在努力找出我突然对NSURLConnection做了什么错事,让它如此恨我


非常感谢您的帮助

虽然我不知道您的问题到底是什么,但我知道在使用NSURLConnection时也会出现随机错误和崩溃。然后我发现,再也没有回头。它是NSURLConnection的替代品,并从CFN网络中运行。它非常稳定(我在我所有的项目中都使用它),并且附带了一些好东西,比如内置进度条支持和部分下载恢复。它甚至可以直接写入磁盘以节省内存,这在iPhone中很重要。

我也在开发者论坛上发布了这个问题,并得到了删除并发的建议。我删除了令人不快的一行:

[NSThread detachNewThreadSelector:@selector(main ) toTarget:selfwithObject:nil];
我也停止重写start,只重写main


NSURLConnection停止崩溃。

刚刚尝试使用ASIHTTPRequest,在尝试解压缩我的响应数据时出错。NSURLConnection从未发生过。