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.