I am working on a project that requires a registration form using a web service for authentication. I have no problem connecting to the server, but it seems that NSURLSession is blocking my user interface, and I really don't know why after a lot of debugging.
For simplicity, here is a short code:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"example.com/service"]];
_sessionLogin = [NSURLSession sharedSession];
NSURLSessionDataTask *sessionDataTaskLogin = [_sessionLogin dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
if(!error)
{
NSLog(@"loginWithSuccess");
UIAlertView *alertError = [[UIAlertView alloc] initWithTitle:@"Login ok" message:@"ok" delegate:self cancelButtonTitle:@"Close" otherButtonTitles: nil];
[alertError show];
}
}];
[sessionDataTaskLogin resume];
_sessionLogin is NSURLSession
When the connection to my server is fast, NSLog (@ "loginWithSuccess") appears almost immediately after I clicked on the login button, but it takes me some time (long time) about 10 seconds, which UIAlertView showed. And I, too, cannot interact with the user interface.
Thanks in advance for each decision.