美文网首页
AFNetworking 网络请求重试机制

AFNetworking 网络请求重试机制

作者: lczalh | 来源:发表于2019-12-03 09:37 被阅读0次

    使用递归方式

    - (void)downloadFileRetryingNumberOfTimes:(NSUInteger)ntimes 
                                    success:(void (^)(id responseObject))success 
                                    failure:(void (^)(NSError *error))failure
    {
        if (ntimes <= 0) {
            if (failure) {
            NSError *error = ...;
            failure(error);
            }
        } else {
            [self getPath:@"/path/to/file" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
                if (success) {
                success(...);
                }
            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                [self downloadFileRetryingNumberOfTimes:ntimes - 1 success:success failure:failure];
            }];
        }
    }
    

    摘录于AFNetworking Issuse

    相关文章

      网友评论

          本文标题:AFNetworking 网络请求重试机制

          本文链接:https://www.haomeiwen.com/subject/fpaqgctx.html