我对网络服务的回应很大,响应时间大约需要一分钟或更多。但NSURLConnectionDelegate方法不会对这些延迟响应做出反应。它没有收到任何数据。我该怎么办?
这是我的代码
-(void)abc:(NSString*)emailId
{
receiveData = [NSMutableData data];
NSString *urlString = [NSString stringWithFormat:@"url"];
NSURL *url = [[NSURL alloc] initWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
**NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:600.0];**
[request setHTTPMethod:@"GET"];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (theConnection) {
NSLog(@"success connection");
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Failed!" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
-(void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *) response
{
[receiveData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receiveData appendData:data];
NSString *str = [[NSString alloc] initWithData:receiveData encoding:NSASCIIStringEncoding];
NSLog(@"response data : %@ ",str);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSXMLParser *xmlparser = [[NSXMLParser alloc] initWithData:receiveData];
[xmlparser setDelegate:xmlparser];
BOOL success = [xmlparser parse];
if (success) {
NSLog(@"successfully parsed 7");
return;
}
}