zoukankan      html  css  js  c++  java
  • 说说iOS 请求重发机制吧。

    半瓶思路,

    不就是重复调用么?写个作用域外的变量不就好了,递减、叠加都可以。。。。

    然鹅,可以用用更漂亮的写法,参数中定义重发次数count,函数内部执行前先判断count,在函数中重新调用时将count-1。

    上代码!!!

    - (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];
            }];
        }
    }

    上边是别人写的,其实还可以给参数count默认值,默认执行一次

    比如这样定义:
    class func post(param : Param?=nil,url: String,ntimes:Int=3)


    思路来源:https://github.com/AFNetworking/AFNetworking/issues/393

     

  • 相关阅读:
    windows 按时自动化任务
    Linux libusb 安装及简单使用
    Linux 交换eth0和eth1
    I.MX6 GPS JNI HAL register init hacking
    I.MX6 Android mmm convenient to use
    I.MX6 GPS Android HAL Framework 调试
    Android GPS GPSBasics project hacking
    Python windows serial
    【JAVA】别特注意,POI中getLastRowNum() 和getLastCellNum()的区别
    freemarker跳出循环
  • 原文地址:https://www.cnblogs.com/madarax/p/9873079.html
Copyright © 2011-2022 走看看