我正在開發一個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對象。 –
您是否嘗試使用「啓用殭屍」來運行您的應用程序以查找可能的內存管理問題? –