我有一个用户将用来登录我的应用程序的登录视图。我使用 NSURLConnection 异步请求块连接到我的 Web 服务并来回传递数据。
我有一个奇怪的问题,如果用户第一次登录,它工作正常。但是如果他们注销,然后尝试再次登录,请求被发送但从不响应(我为所有场景设置了警报视图;即超时、数据 = nil、错误!= nil 等)。它只是与我显示的加载屏幕一起坐在那里,从不做任何事情。
我只是错过了什么吗?
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
if ([data length] > 0 && error == nil){
if( data != nil ) {
//Handle Data Here
.............
} else {
[loadingView removeFromSuperview];
loadingView = nil;
BlockAlertView *alert = [BlockAlertView alertWithTitle:@"Network Error" message:@"Network connection was successful, but there was a problem with data transfer.\nPlease try again."];
[alert setCancelButtonWithTitle:@"OK" block:nil];
[alert show]; }
}
else if ([data length] == 0 && error == nil){
[loadingView removeFromSuperview];
loadingView = nil;
BlockAlertView *alert = [BlockAlertView alertWithTitle:@"Network Error" message:@"Network connection was successful, but there was a problem with data transfer.\nPlease try again."];
[alert setCancelButtonWithTitle:@"OK" block:nil];
[alert show];
}
else if (error != nil && error.code == NSURLErrorTimedOut){
[loadingView removeFromSuperview];
loadingView = nil;
BlockAlertView *alert = [BlockAlertView alertWithTitle:@"Network Error" message:@"The network request timed out.\nPlease check your internet connection and try again."];
[alert setCancelButtonWithTitle:@"OK" block:nil];
[alert show];
}
else if (error != nil){
[loadingView removeFromSuperview];
loadingView = nil;
BlockAlertView *alert = [BlockAlertView alertWithTitle:@"Network Error" message:@"There was a problem connecting to the network.\nPlease check your internet connection and try again."];
[alert setCancelButtonWithTitle:@"OK" block:nil];
[alert show];
}
}];