Вопрос

Is it possible to set one common action for all failed requests in RestKit? I need to stop ajax spinner for those cases but I don't want to repeat this line of code in every callback (I have too many).

UPDATE: request example:

[_manager postObject:message path:@"/messages.json" parameters:nil success:^
 (RKObjectRequestOperation *operation, RKMappingResult *result) {
     Message *message = result.firstObject;
     callback(message);
 } failure:^(RKObjectRequestOperation *operation, NSError *error) {
     failureCallback();
}];

And for errors I mean responses from server with status codes in 400..511 range

Это было полезно?

Решение

You can subclass the object manager and override each method to call super but wrapping the supplied failure callback in a custom block which adds your common logic.

Другие советы

You can do it in completion block of Request Operations Queue, completion block is going to call up when queue operations are failed :

[objectManager enqueueBatchOfObjectRequestOperations:requestOperations progress: ^(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations) {
} completion: ^(NSArray *operations) {
 //.. Stop Spinner Code

}];
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top