Rams
Rams

Reputation: 1751

NSURLConnection Delegates problem

NSURLConnection delegate method is not called (didReceiveResponse,connectionDidFinishLoading etc) .when i am using a same class delegate methods called properly

category *cat = [[category alloc]init];  
    [cat getcategory:@"1088"]; 

in a category page

(void) getcategory: (NSString *) catid {
[...]

 NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:urlrequest delegate:self];  

        NSHTTPURLResponse *response;  
       [NSURLConnection sendSynchronousRequest: urlrequest returningResponse: &response error: nil];   

        if( theConnection )  
        {  
            webData = [[NSMutableData data] retain];  
        }  
        else  
        {  
            NSLog(@"theConnection is NULL");  
        }  

    }  

    -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    {   
        [webData setLength: 0];  
    }  
    -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data  
    {  
        [webData appendData:data];  
    }  
    -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    {  
        NSLog(@"ERROR with theConenction");  
        [connection release];  
        [webData release];  
    }  
    -(void)connectionDidFinishLoading:(NSURLConnection *)connection
    {  
        NSLog(@"DONE. Received Bytes: %d", [webData length]);  
        NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:  [webData length] encoding:NSUTF8StringEncoding];  
    }

Upvotes: 0

Views: 562

Answers (1)

alex-i
alex-i

Reputation: 5454

you're using the same request into 2 different connections: theConnection (which is asynchronous and with delegate set up - the connections starts when you init it) and [NSURLConnection sendSynchronousRequest: urlrequest returningResponse: &response error: nil];. Try removing the second

Upvotes: 1

Related Questions