序列请求Restkit 0.20

时间:2014-01-15 02:21:52

标签: ios session restkit afnetworking restkit-0.20

环境: - MyViewController(相同的ViewController)

使用RKObjectManagerAFHTTPClient* client)的引用。

1 - 第一次请求

[client setDefaultHeader:@"api_key" value:session.getApi_Key];
[client setDefaultHeader:@"Content-Length" value:postLength];
[client setDefaultHeader:@"Content-Type" value:@"application/x-www-form-urlencoded"];
[client setDefaultHeader:@"signature" value:signature];
[client setDefaultHeader:@"date" value:date];

[[RKObjectManager sharedManager] postObject:nil
                                       path:[SMRequestFactory getTokenRequestPath]
                                 parameters:[SMRequestFactory getTokenRequestParams: self.usuario.text : self.senha.text]
                                    success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { **Call request 2** }
                                    failure:^(RKObjectRequestOperation *operation, NSError *error) {...}];

2 - 第二次请求

[client setDefaultHeader:@"api_key" value:session.getApi_Key];
[client setDefaultHeader:@"access_token" value:session.getAccessToken];
[client setDefaultHeader:@"signature" value:session.getSignature];
[client setDefaultHeader:@"date" value:session.getData];

[[RKObjectManager sharedManager] postObject:nil
                                       path:[SMRequestFactory getLoginRequestPath]
                                 parameters:[SMRequestFactory getLoginRequestParams]
                                    success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { **Call request 3** }
                                    failure:^(RKObjectRequestOperation *operation, NSError *error) {...}];

3 - 第三次请求操作超时

[client setDefaultHeader:@"api_key" value:session.getApi_Key];
[client setDefaultHeader:@"access_token" value:session.getAccessToken];
[client setDefaultHeader:@"signature" value:session.getSignature];
[client setDefaultHeader:@"date" value:session.getData];

[[RKObjectManager sharedManager] getObjectsAtPath:[SMRequestFactory getUsuariosRequestPath]
                                       parameters:nil
                                          success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult){ }
                                          failure:^(RKObjectRequestOperation *operation, NSError *error) {}];

如果按照顺序执行,则第三个请求:服务器接收并响应,但60秒后发生超时。

即使按下按钮(不是之前的成功),如果按照顺序,第三个请求也会超时。

首先调用第三个请求。

1 个答案:

答案 0 :(得分:0)

不是在成功代码块中对您的请求进行“排序/链接”,而是尝试通过GCD异步调度来调用它?

dispatch_queue_t myQueue = dispatch_queue_create("My Queue",NULL);
dispatch_async(myQueue, ^{
    // Call next request
}); 

http://jeffreysambells.com/2013/03/01/asynchronous-operations-in-ios-with-grand-central-dispatch