(NSProgress * _Nonnull downloadProgress)加网络封装

[[self GETManage] GET:ready_exchange_list_URL parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {
        //不起作用
        [dataTableView endLoad];
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable 

progress是进程,一般来讲是用不上的,这里面并不是网络一回来的就触发的,所以不能在这里做 [dataTableView endLoad];

不过值得一提的是,

项目一般要对网络接口统一处理

   NSURLSessionTask *task = [[GSNetwork shareManager].afHTTPSessionManager GET:basicUrlString parameters:[GSNetworkAssist addCommonParameters:mutableParameters] progress:
                              ^(NSProgress * _Nonnull downloadProgress) {
                                  
                              } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                                  [self handleResponseWithHandler:responseHandler jsonResult:responseObject task:task];
                              } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                                  [self handleResponseWithHandler:responseHandler jsonResult:nil task:task];
                              }];
    
    return task;
+ (void)handleResponseWithHandler:(GSNetworkResponseHandler)handler
                       jsonResult:(NSDictionary *)jsonResult
                             task:(NSURLSessionTask *)task {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSDictionary *afterCheckResult = [GSNetworkAssist checkResult:jsonResult response:task.response];
        if (handler) {
            GSNetworkResponse *r = [[GSNetworkResponse alloc] initWithJsonResult:afterCheckResult response:task.response];
            handler(r);
        }
    });
}

这就有点屌了,我之前一直以为只能在单层的block里面回调触发,原来也可在block的block里面触发。牛逼

你可能感兴趣的:((NSProgress * _Nonnull downloadProgress)加网络封装)