1

My response to a web-service is huge and takes about a minute or a little more for the response. But the NSURLConnectionDelegate methods don't respond to these delayed response. It doesnt receive any data. What do i do ?

Here is my code

-(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;
    } 

}
Sharanya K M
  • 1,805
  • 4
  • 23
  • 44

0 Answers0