mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-01-12 22:51:50 +08:00
Rework notifications to allow request queue to observe only the requests it dispatches instead of all of them. Fixes incorrectly decrementing loading count.
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
extern NSString* const RKRequestSentNotification;
|
||||
extern NSString* const RKRequestDidLoadResponseNotification;
|
||||
extern NSString* const RKResponseReceivedNotification;
|
||||
extern NSString* const RKRequestReceivedResponseNotification;
|
||||
extern NSString* const RKRequestFailedWithErrorNotification;
|
||||
|
||||
extern NSString* const RKServiceDidBecomeUnavailableNotification;
|
||||
@@ -12,4 +12,4 @@ NSString* const RKRequestSentNotification = @"RKRequestSentNotification";
|
||||
NSString* const RKRequestDidLoadResponseNotification = @"RKRequestDidLoadResponseNotification";
|
||||
NSString* const RKRequestFailedWithErrorNotification = @"RKRequestFailedWithErrorNotification";
|
||||
NSString* const RKServiceDidBecomeUnavailableNotification = @"RKServiceDidBecomeUnavailableNotification";
|
||||
NSString* const RKResponseReceivedNotification = @"RKResponseReceivedNotification";
|
||||
NSString* const RKRequestReceivedResponseNotification = @"RKRequestReceivedResponseNotification";
|
||||
|
||||
@@ -439,7 +439,9 @@
|
||||
|
||||
// NOTE: This notification must be posted last as the request queue releases the request when it
|
||||
// receives the notification
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKResponseReceivedNotification object:response userInfo:nil];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKRequestReceivedResponseNotification
|
||||
object:self
|
||||
userInfo:nil];
|
||||
}
|
||||
|
||||
- (BOOL)isGET {
|
||||
|
||||
@@ -139,7 +139,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
selector:@selector(loadNextInQueue)
|
||||
userInfo:nil
|
||||
repeats:NO];
|
||||
RKLogDebug(@"Timer initialized with delay %f for queue %@", kFlushDelay, self);
|
||||
RKLogTrace(@"Timer initialized with delay %f for queue %@", kFlushDelay, self);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(responseDidLoad:)
|
||||
name:RKResponseReceivedNotification
|
||||
name:RKRequestReceivedResponseNotification
|
||||
object:request];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(responseDidLoad:)
|
||||
@@ -244,7 +244,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
RKLogTrace(@"Removing request %@ from queue %@", request, self);
|
||||
[_requests removeObject:request];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:RKResponseReceivedNotification object:request];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:RKRequestReceivedResponseNotification object:request];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:RKRequestFailedWithErrorNotification object:request];
|
||||
|
||||
if (decrementCounter) {
|
||||
@@ -330,15 +330,9 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
* the completed request from the queue and continue processing
|
||||
*/
|
||||
- (void)responseDidLoad:(NSNotification*)notification {
|
||||
if (notification.object) {
|
||||
|
||||
if (notification.object) {
|
||||
// Get the RKRequest, so we can check if it is from this RKRequestQueue
|
||||
RKRequest *request = nil;
|
||||
if ([notification.object isKindOfClass:[RKResponse class]]) {
|
||||
request = [(RKResponse*)notification.object request];
|
||||
} else if ([notification.object isKindOfClass:[RKRequest class]]) {
|
||||
request = (RKRequest*)notification.object;
|
||||
}
|
||||
RKRequest *request = (RKRequest*)notification.object;
|
||||
|
||||
// Our RKRequest completed and we're notified with an RKResponse object
|
||||
if (request != nil && [self containsRequest:request]) {
|
||||
|
||||
@@ -69,8 +69,8 @@
|
||||
|
||||
if (successful) {
|
||||
_isLoaded = YES;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKResponseReceivedNotification
|
||||
object:_response
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKRequestReceivedResponseNotification
|
||||
object:self
|
||||
userInfo:nil];
|
||||
} else {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKRequestFailedWithErrorNotification
|
||||
|
||||
@@ -42,6 +42,7 @@ static NSString* const kDBAccessTokenHTTPHeaderField = @"X-USER-ACCESS-TOKEN";
|
||||
@synthesize window;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
// Initialize the RestKit Object Manager
|
||||
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:DBRestKitBaseURL];
|
||||
|
||||
@@ -158,9 +159,11 @@ static NSString* const kDBAccessTokenHTTPHeaderField = @"X-USER-ACCESS-TOKEN";
|
||||
|
||||
See RKLog.h and lcl_log_components.h for details on the logging macros available
|
||||
*/
|
||||
RKLogConfigureByName("RestKit", RKLogLevelTrace);
|
||||
RKLogConfigureByName("RestKit/Network", RKLogLevelDebug);
|
||||
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelDebug);
|
||||
// RKLogConfigureByName("RestKit", RKLogLevelTrace);
|
||||
// RKLogConfigureByName("RestKit/Network", RKLogLevelDebug);
|
||||
// RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelDebug);
|
||||
|
||||
RKLogConfigureByName("RestKit/Network/Queue", RKLogLevelTrace);
|
||||
|
||||
// Enable boatloads of trace info from the mapper
|
||||
// RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
|
||||
|
||||
Reference in New Issue
Block a user