ios 中尝试多次请求

-(void)tryRun

{

    tryTimes++;

    id obj = [ASODataManager getAppleAccount];

    if (obj) {

        __block FirstViewController* sf = self;

        //有账号,可以开始获取数据

        [[ASODataManager sharedManager] fetchASOTaskListWithCompletionHandler:^(NSArray *data) {

            NSMutableArray* arr = [[NSMutableArray alloc] initWithCapacity:[data count]];

            for (id obj in data) {

                if ([[obj objectForKey:@"isFinished"] integerValue] == 0) {

                    [arr addObject:obj];

                }

            }

            

            sf->task = [arr copy];

            if ([sf->task count] <= 0) {

//                [[[UIAlertView alloc] initWithTitle:@"提示" message:@"当前无任务" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];

                [[KengSDKToolsiToast makeText:@"当前无任务"] show];

            }

            [sf.MainTableView reloadData];

        }];

    }else{

        //没有账号,连续三次

        if (tryTimes <= 3) {

            [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(tryRun) userInfo:nil repeats:NO];

        }

        

    }

 

}

posted on 2016-05-28 08:39  许广  阅读(310)  评论(0编辑  收藏  举报