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