嘿guyz我有关于NSUrlConnection的这个问题我发起了这样的请求
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:URL_PACKAGE,2]]];
Communication *comm = [[Communication alloc] initWithUrlRequest:request];
comm.request_name = request_name;
comm.delegate = self;
[comm startAsynchronous];
[request release];
然后获得代码的响应很好但是你可以看到我创建了一个通信类来建立连接,当我请求不同的Web服务时它
- (Communication *) initWithUrlRequest:(NSMutableURLRequest *)url_request {
self.request = url_request;
return self;
}
-(void)dealloc {
[super dealloc];
}
- (void) startAsynchronous {
responseData = [[NSMutableData data] retain];
NSLog(@"%@",[request URL]);
downloadConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
}
-(void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response {
[responseData setLength:0];
if ( [[self delegate] respondsToSelector:@selector(communication:didReceiveResponse:RequestName:)] ) {
[self.delegate communication:self didReceiveResponse:response RequestName:self.request_name];
}
}
-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data {
[responseData appendData:data];
if ( [[self delegate] respondsToSelector:@selector(communication:didReceiveData:RequestName:)] ) {
[self.delegate communication:self didReceiveData:data RequestName:self.request_name];
}
}
-(void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error {
[self.delegate communication:self didFailWithError:error RequestName:self.request_name];
NSLog(@"%@", error);
}
-(void)connectionDidFinishLoading:(NSURLConnection*)connection {
NSString *responseString = [[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] autorelease];
[responseData release];
responseString = [responseString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
responseString = [responseString stringByReplacingOccurrencesOfString:@"+" withString:@" "];
responseString = [responseString stringByReplacingOccurrencesOfString:@"null" withString:@"\"\""];
[self.delegate communication:self didFinishWithString:responseString RequestName:self.request_name];
}
错误是
2013-07-30 13:55:46.994 Ipad Qld[3982:c07] *** -[Requests respondsToSelector:]: message sent to deallocated instance 0xa16b310