我正在开发一个IOS应用程序。 didReceiveResponse中的setLength方法崩溃。你觉得是什么原因呢。我应该做什么预防。NSData setLength EXC_BAD_ACCESS
- (void) callService:(NSString*)urlString
{
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL urlString]];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[urlString dataUsingEncoding:NSUTF8StringEncoding]];
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection) {
self.webData = [[NSMutableData data] retain];
}
else {
NSLog(@"connection is NULL");
}
}
#pragma mark Web service
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[self.webData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[self.webData appendData:data];
}
检查您的控制台...您正在获取'connection is NULL'打印 –
异常消息指出setLenght:在*数组*上调用。在didReceiveResponse中设置断点并检查self.webData对象。 –
您是否尝试使用“启用僵尸”来运行您的应用程序以查找可能的内存管理问题? –