0
我使用AFNetworking + SVProgressHUD post
来请求数据。 SVProgressHUD
将始终显示,如果网络有问题或非常缓慢和互联网链接已被切断。AFNetworking如何加入请求超时和网络不通验证?
AFNetworking
如何判断网络问题?或请求超时?
我使用AFNetworking + SVProgressHUD post
来请求数据。 SVProgressHUD
将始终显示,如果网络有问题或非常缓慢和互联网链接已被切断。AFNetworking如何加入请求超时和网络不通验证?
AFNetworking
如何判断网络问题?或请求超时?
我不确定SVProgressHUD的实现是什么,但我在当前的应用程序中使用了一个名为MBProgressHUD的类似工具。希望这个建议仍然适用。
如果我正确理解你的问题,你想知道如何解雇你的progressHUD如果AFNetworking调用失败?如果这是你的问题,那么你所需要做的就是在你的失败区中关闭你的HUD,如下所示。
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[navigationController.view addSubview:HUD];
HUD.dimBackground = YES;
[HUD show:YES];
//Set up the request
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"example.com"]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url];
[request setHTTPMethod:@"POST"];
//Set up the operation
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// Hide activity indicator after success
[HUD show:NO];
[HUD hide:YES];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// Hide activity indicator after failure
[HUD show:NO];
[HUD hide:YES];
}];
// Fire off the operation
[operation start];