如何多次调用同一服务并将数据存储在ios中

时间:2019-07-16 13:18:02

标签: ios objective-c web-services afnetworking

我有一种情况,我将从Web服务中获取25000条记录,它是使用分页技术发送的。  所以问题是我只想存储数据,因此我想循环运行它,但将来记录可能会有所不同(即30000,50000等)

我从后端获得每页10000条记录,但是我不知道我运行了多少次循环,所以我该如何处理这个问题?

__m256d

上面是我卡住的地方。

任何建议都会受到赞赏。

1 个答案:

答案 0 :(得分:0)

您可以将数据存储到sqlite数据库中。对于递归调用服务,您可以修改与以下方法相同的方法,

-(void)vendorsListCalling:(NSInteger)pageIndex {

    if (!loader) {
        //Write code to Show your loader here
    }

    [[ServicesHandler new] callVendorDetailsServiceWithParams:@{@"pageno":@(pageIndex)} CompletionBLock:^(NSDictionary *response, NSError *error) {
        if (error) {
            NSLog(@"error log  %@",error.localizedDescription);

            //If it fails you need to call the service again with the same Index
            [self vendorsListCalling:pageCount];

        } else {
            if (!response[@"params"][@"data"]) {
                //Stop loader since you didn't received any data
            } else {
                NSDictionary *dict = response[@"params"][@"data"];
                [vendorDictionay addEntriesFromDictionary:dict];
                pageCount++;

                // Store Data in database here //

                //Call service with incremented Index
                [self vendorsListCalling:pageCount];
            }
        }
    }];
}
相关问题