mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-22 11:46:05 +08:00
Add cancellation API to RKObjectManager.
* Introduces `cancelAllObjectRequestOperationsWithMethod:pathPattern:` * Make RKObjectRequestOperation cancel underlying request operation when cancelled
This commit is contained in:
@@ -144,9 +144,6 @@ RKMappingResult, RKRequestDescriptor, RKResponseDescriptor;
|
||||
|
||||
RestKit features deep integration with Apple's Core Data persistence framework. The object manager provides access to this integration by creating `RKManagedObjectRequestOperation` objects when an attempt is made to interact with a resource that has been mapped using an `RKEntityMapping`. To utilize the Core Data integration, the object manager must be provided with a fully configured `RKManagedObjectStore` object. The `RKManagedObjectStore` provides access to the `NSManagedObjectModel` and `NSManagedObjectContext` objects required to peform object mapping that targets a Core Data entity.
|
||||
|
||||
Fetch Request Blocks ->> TODO
|
||||
Need to cover DELETE impacts...
|
||||
|
||||
Please see the documentation for `RKManagedObjectStore`, `RKEntityMapping`, and `RKManagedObjectRequestOperation` for in depth information about Core Data in RestKit.
|
||||
*/
|
||||
@interface RKObjectManager : NSObject
|
||||
@@ -396,7 +393,18 @@ RKMappingResult, RKRequestDescriptor, RKResponseDescriptor;
|
||||
@param objectRequestOperation The object request operation to be enqueued.
|
||||
*/
|
||||
- (void)enqueueObjectRequestOperation:(RKObjectRequestOperation *)objectRequestOperation;
|
||||
// TODO: Need a cancel...
|
||||
|
||||
/**
|
||||
Cancels all operations in the object manager's operation queue whose requests match the specified HTTP method and path pattern.
|
||||
|
||||
Paths are matches against the `path` of the `NSURL` of the `NSURLRequest` of each `RKObjectRequestOperation` contained in the receiver's operation queue using a `RKPathMatcher` object.
|
||||
|
||||
@param method The HTTP method to match for the cancelled requests, such as `RKRequestMethodGET`, `RKRequestMethodPOST`, `RKRequestMethodPUT`, `RKRequestMethodPatch`, or `RKRequestMethodDELETE`. If `RKRequestMethodAny`, all object request operations with URLs matching the given path pattern will be cancelled.
|
||||
@param pathPattern The pattern to match against the path of the request URL for executing object request operations considered for cancellation.
|
||||
|
||||
@see `RKPathMatcher`
|
||||
*/
|
||||
- (void)cancelAllObjectRequestOperationsWithMethod:(RKRequestMethod)method matchingPathPattern:(NSString *)pathPattern;
|
||||
|
||||
///-------------------------------------
|
||||
/// @name Making Object Requests by Path
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#import "RKMIMETypes.h"
|
||||
#import "RKLog.h"
|
||||
#import "RKMIMETypeSerialization.h"
|
||||
#import "RKPathMatcher.h"
|
||||
|
||||
#if !__has_feature(objc_arc)
|
||||
#error RestKit must be built with ARC.
|
||||
@@ -516,6 +517,22 @@ NSURL *RKBaseURLAssociatedWithURL(NSURL *URL)
|
||||
[self.operationQueue addOperation:objectRequestOperation];
|
||||
}
|
||||
|
||||
- (void)cancelAllObjectRequestOperationsWithMethod:(RKRequestMethod)method matchingPathPattern:(NSString *)pathPattern
|
||||
{
|
||||
NSString *methodName = RKStringFromRequestMethod(method);
|
||||
RKPathMatcher *pathMatcher = [RKPathMatcher pathMatcherWithPattern:pathPattern];
|
||||
for (NSOperation *operation in [self.operationQueue operations]) {
|
||||
if (![operation isKindOfClass:[RKObjectRequestOperation class]]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSURLRequest *request = [(RKObjectRequestOperation *)operation request];
|
||||
if ((!methodName || [methodName isEqualToString:[request HTTPMethod]]) && [pathMatcher matchesPath:[[request URL] path] tokenizeQueryStrings:NO parsedArguments:nil]) {
|
||||
[operation cancel];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NSString *RKStringFromNetworkReachabilityStatus(AFNetworkReachabilityStatus networkReachabilityStatus)
|
||||
|
||||
@@ -192,6 +192,12 @@ static NSIndexSet *RKObjectRequestOperationAcceptableMIMETypes()
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)cancel
|
||||
{
|
||||
[super cancel];
|
||||
[self.requestOperation cancel];
|
||||
}
|
||||
|
||||
- (void)main
|
||||
{
|
||||
if (self.isCancelled) return;
|
||||
@@ -212,6 +218,8 @@ static NSIndexSet *RKObjectRequestOperationAcceptableMIMETypes()
|
||||
self.error = self.requestOperation.error;
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.isCancelled) return;
|
||||
|
||||
// Map the response
|
||||
NSError *error;
|
||||
|
||||
Reference in New Issue
Block a user