小编Mat*_*bbi的帖子

如何重试基于块的URL请求

我使用iOS7的新URL请求方法获取数据,如下所示:

NSMutableURLRequest *request = [NSMutableURLRequest
    requestWithURL:[NSURL URLWithString:[self.baseUrl 
    stringByAppendingString:path]]];

NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
    NSUInteger responseStatusCode = [httpResponse statusCode];

    if (responseStatusCode != 200) { 
        // RETRY (??????) 
    } else       
        completionBlock(results[@"result"][symbol]);
}];
[dataTask resume];
Run Code Online (Sandbox Code Playgroud)

不幸的是,我不时收到HTTP响应,表明服务器无法访问(response code != 200)并需要向服务器重新发送相同的请求.

如何才能做到这一点?我如何完成上面评论所在的代码片段// RETRY

在我的示例中,我在成功获取后调用完成块.但是如何再次发送相同的请求呢?

谢谢!

cocoa objective-c nsurlrequest ios

11
推荐指数
2
解决办法
7483
查看次数

获得本季度的第一个日期

我正在尝试获取当前季度的第一个和最后一个日期,我正在使用它:

NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitQuarter | NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]];

components.quarter = 1;

funStartDate = [[NSCalendar currentCalendar] dateFromComponents: components];
NSLog(@"First day of quater: %@", funStartDate);

[components setQuarter:[components quarter]+1];

funEndDate = [[NSCalendar currentCalendar] dateFromComponents: components];
NSLog(@"Last day of quater: %@", [funEndDate descriptionWithLocale:[NSLocale currentLocale]]);
Run Code Online (Sandbox Code Playgroud)

但在两个控制台打印中,我看到了今天的日期.我做错了什么?

nsdate nscalendar ios

5
推荐指数
2
解决办法
1755
查看次数

使用SQL'with'子句时出错

这是我正在使用的查询.我收到此查询错误.'WITH'子句附近的语法错误.

WITH RECURSIVE under_cust (affiliation_id, from_customer_id, to_customer_id, to_name,     parent_customer_type, child_customer_type, level) 
 AS (SELECT af.affiliation_id, 
       from_customer_id, 
       to_customer_id, 
       to_name, 
       parent_customer_type, 
       child_customer_type, 
       0 LEVEL 
     FROM   affiliation af, 
                customer c 
         WHERE  to_customer_id <> from_customer_id 
                AND af.from_customer_id = c.customer_id 
                AND af.to_customer_id = 1000022559337 
         UNION ALL 
         SELECT af.affiliation_id, 
                af.from_customer_id, 
                af.to_customer_id, 
                af.to_name, 
                af.parent_customer_type, 
                af.child_customer_type, 
                under_cust.level + 1 LEVEL 
         FROM   customer c, 
                affiliation af 
                JOIN under_cust smr 
                  ON smr.from_customer_id = af.to_customer_id 
         WHERE  af.from_customer_id = c.customer_id 
) SELECT affiliation_id, 
   to_customer_id   parent, 
   from_customer_id child, 
   to_name, 
   parent_customer_type, 
   child_customer_type, 
   level 
FROM   under_cust 
Run Code Online (Sandbox Code Playgroud)

sqlite

3
推荐指数
1
解决办法
5202
查看次数

标签 统计

ios ×2

cocoa ×1

nscalendar ×1

nsdate ×1

nsurlrequest ×1

objective-c ×1

sqlite ×1