I am having a Server Class which has delegate methods of NSURLConnection. And I am having another class named SendRequest which will send the NSMutableURLRequest to the Server Class.
In Server Class I am having two methods called
- (void)executeAsync:(NSMutableURLRequest)urlRequest timeOutInterval:(int)timeOut
{
_urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self startImmediately:YES];];
}
- (void)executeSync:(NSMutableURLRequest)urlRequest
{
NSData* respData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
}
Everything works fine until here , I am able to call the above executeAsync method from SendRequest class, which is calling the delegate methods.
Now I have added a new method in the SendRequest class which will call the executeRequest method in Server class.
- (void)executeRequest:(NSMutableURLRequest)urlRequest
{
_urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self startImmediately:YES];];
}
This time , I got trapped . executeRequest method is getting called but it is not calling its delegate methods while processing the URL request. I am struck here for many hours.
Everything seems to be correct , I am sending the urlRequest the same way I used to send before. But I don’t know why it is not working. Feel free comment , but please help me. I am really worried
EDIT :
I need to post a request to the server and get a response . If I try with synchronous it is working fine,but it is blocking the main thread. Thats the reason I am going for the asynchronous. Through delegate methods I am trying to get the response data.
I finally solved it. Hope this will help some-one. I made code clean up and declared methods properly and finally while creating the object for the class , I have to use initwithDelegate:self . And finally NSURLConnection delegate methods are called .