设置方法如下: 在封装的网络请求类里面如下设置 AFWEBAPI_REQUEST_TIMEOUT 这个参数为超时时间 #define AFWEBAPI_REQUEST_TIMEOUT 20#pragma mark - 单例 构造函数+ (instancetype)sharedTools { static WXNetworkTool
          设置方法如下:
在封装的网络请求类里面如下设置
AFWEBAPI_REQUEST_TIMEOUT 这个参数为超时时间
#define AFWEBAPI_REQUEST_TIMEOUT 20
#pragma mark - 单例 & 构造函数
+ (instancetype)sharedTools {
 static WXNetworkTools *instance;
 static dispatch_once_t onceToken;
 dispatch_once(&onceToken, ^{
  instance = [[self alloc] initWithBaseURL:[NSURL URLWithString:WX_SERVER_URL]];
  instance.requestSerializer.timeoutInterval = AFWEBAPI_REQUEST_TIMEOUT;
 });
 return instance;
}
在封装的方法里面,在失败的回调里面写下如下代码,至于怎么处置就看自己了,我这里具体需求没有给,我先做了一个弹框处理
/// @param finished 完成回调
- (void)requestWithMethod:(WXRequestMethod)method URLString:(NSString *)URLString parameters:(id)parameters finished:(WXRequestCallBack)finished {
 NSString *methodName = (method == GET) ? @"GET" : @"POST";
 NSLog(@"%@",URLString);
 [[self dataTaskWithHTTPMethod:methodName URLString:URLString parameters:parameters uploadProgress:nil downloadProgress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  finished(responseObject, nil);
  if (responseObject[@"status"] && [responseObject[@"status"] integerValue] == 1000) {
   //这里来账号互踢
   [[NSNotificationCenter defaultCenter] postNotificationName:KMutualKickNotification object:nil];
   return;
  }
 } failure:^(NSURLSessionDataTask *task, NSError *error) {
  NSLog(@"网络请求错误 %@", error);
  //这里来处理网络超时
  if (error.code == -1001) {
   [SVProgressHUD showErrorWithStatus:@"网络超时!"];
   return ;
  }
  finished(nil, error);
 }] resume];
}
如何去调试呢,难道去电梯里面去调试吗?
下面截图教你们如何去做网络限制去摸你用户网络不好的情况
使用工具:charles(青花瓷)
顶端的工具条--》Proxy --》Throttling Settting
设置好之后千万要记得去勾选Throttling,不然没有效果
顶端的工具条--》Proxy --》Throttling


这样就ok了
总结
以上就是这篇文章的全部内容了,希望本文的内容对各位iOS开发者们能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对自由互联的支持。
