0

I am using AFNetworking ,the code is working well but none of the delegate nethods of NSURLConnectionDelegate methods are being called after making successful connection.

I have declared in my interface file as delegate of NSURLConnection too.But nothing seems working ,is it something issue with working with background threads and main thread? Here is my code:

NSLog(@"\n\n1 Is main thread %@", ([NSThread isMainThread] ? @"Yes" : @" NOT"));

AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];

 manager.responseSerializer.acceptableContentTypes= [NSSet setWithObject:@"text/html"];





 NSDictionary *parameters = @{
                             @"email": [Constants sharedInstance].email,

                             @"password": [Constants sharedInstance].password,

                             };

 NSLog(@"\n\nparameters:   %@",parameters);



 [manager POST:@"https://anyurl/" parameters:parameters success:^

 (AFHTTPRequestOperation *operation, id responseObject) {


   //  [operation setRunLoopModes:[NSSet setWithObject:NSDefaultRunLoopMode]];

     NSLog(@"\n\n 2 Is main thread %@", ([NSThread isMainThread] ? @"Yes" : @" NOT"));


     [self stopLoading];

     NSLog(@"\n\nconnection successful!!");

    NSLog(@"\n\nJSON: %@", responseObject);

 }

      failure:^(AFHTTPRequestOperation *operation, NSError *error) {

 NSLog(@"\n\nError: %@", error);

 [self stopLoading];


 NSLog(@"Connection could not be made");

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Network" message:@"Cannot make connection to the server" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];

 [alert show];



      }
   ];

  NSLog(@"\n\n 3 Is main thread %@", ([NSThread isMainThread] ? @"Yes" : @" NOT"));

  [self startLoading];


  NSLog(@"\n\n4 Is main thread %@", ([NSThread isMainThread] ? @"Yes" : @" NOT"));

I saw this link but not able to use that answer.

Community
  • 1
  • 1
SandeepAggarwal
  • 1,273
  • 3
  • 14
  • 38

1 Answers1

0

AFNetworking is a separate library if you use AFNetworking its success and failure block will be executed. If you want to execute NSURLConnectionDelegate methods, use NSURLConnection instead of AFNetwork

Rafeek
  • 523
  • 3
  • 16
  • thanx for the info, but I want to call functions like didRecieveData on successful connection ,then how to call them? – SandeepAggarwal Jul 06 '14 at 18:24
  • Also how come all such related posts are valid then? http://stackoverflow.com/q/14836948/3632958 http://stackoverflow.com/q/20143951/3632958 – SandeepAggarwal Jul 06 '14 at 18:59