mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-29 21:25:51 +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 RKRequestSentNotification;
|
||||||
extern NSString* const RKRequestDidLoadResponseNotification;
|
extern NSString* const RKRequestDidLoadResponseNotification;
|
||||||
extern NSString* const RKResponseReceivedNotification;
|
extern NSString* const RKRequestReceivedResponseNotification;
|
||||||
extern NSString* const RKRequestFailedWithErrorNotification;
|
extern NSString* const RKRequestFailedWithErrorNotification;
|
||||||
|
|
||||||
extern NSString* const RKServiceDidBecomeUnavailableNotification;
|
extern NSString* const RKServiceDidBecomeUnavailableNotification;
|
||||||
@@ -12,4 +12,4 @@ NSString* const RKRequestSentNotification = @"RKRequestSentNotification";
|
|||||||
NSString* const RKRequestDidLoadResponseNotification = @"RKRequestDidLoadResponseNotification";
|
NSString* const RKRequestDidLoadResponseNotification = @"RKRequestDidLoadResponseNotification";
|
||||||
NSString* const RKRequestFailedWithErrorNotification = @"RKRequestFailedWithErrorNotification";
|
NSString* const RKRequestFailedWithErrorNotification = @"RKRequestFailedWithErrorNotification";
|
||||||
NSString* const RKServiceDidBecomeUnavailableNotification = @"RKServiceDidBecomeUnavailableNotification";
|
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
|
// NOTE: This notification must be posted last as the request queue releases the request when it
|
||||||
// receives the notification
|
// receives the notification
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKResponseReceivedNotification object:response userInfo:nil];
|
[[NSNotificationCenter defaultCenter] postNotificationName:RKRequestReceivedResponseNotification
|
||||||
|
object:self
|
||||||
|
userInfo:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isGET {
|
- (BOOL)isGET {
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
|||||||
selector:@selector(loadNextInQueue)
|
selector:@selector(loadNextInQueue)
|
||||||
userInfo:nil
|
userInfo:nil
|
||||||
repeats:NO];
|
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
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(responseDidLoad:)
|
selector:@selector(responseDidLoad:)
|
||||||
name:RKResponseReceivedNotification
|
name:RKRequestReceivedResponseNotification
|
||||||
object:request];
|
object:request];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(responseDidLoad:)
|
selector:@selector(responseDidLoad:)
|
||||||
@@ -244,7 +244,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
|||||||
RKLogTrace(@"Removing request %@ from queue %@", request, self);
|
RKLogTrace(@"Removing request %@ from queue %@", request, self);
|
||||||
[_requests removeObject:request];
|
[_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];
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:RKRequestFailedWithErrorNotification object:request];
|
||||||
|
|
||||||
if (decrementCounter) {
|
if (decrementCounter) {
|
||||||
@@ -330,15 +330,9 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
|||||||
* the completed request from the queue and continue processing
|
* the completed request from the queue and continue processing
|
||||||
*/
|
*/
|
||||||
- (void)responseDidLoad:(NSNotification*)notification {
|
- (void)responseDidLoad:(NSNotification*)notification {
|
||||||
if (notification.object) {
|
if (notification.object) {
|
||||||
|
|
||||||
// Get the RKRequest, so we can check if it is from this RKRequestQueue
|
// Get the RKRequest, so we can check if it is from this RKRequestQueue
|
||||||
RKRequest *request = nil;
|
RKRequest *request = (RKRequest*)notification.object;
|
||||||
if ([notification.object isKindOfClass:[RKResponse class]]) {
|
|
||||||
request = [(RKResponse*)notification.object request];
|
|
||||||
} else if ([notification.object isKindOfClass:[RKRequest class]]) {
|
|
||||||
request = (RKRequest*)notification.object;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Our RKRequest completed and we're notified with an RKResponse object
|
// Our RKRequest completed and we're notified with an RKResponse object
|
||||||
if (request != nil && [self containsRequest:request]) {
|
if (request != nil && [self containsRequest:request]) {
|
||||||
|
|||||||
@@ -69,8 +69,8 @@
|
|||||||
|
|
||||||
if (successful) {
|
if (successful) {
|
||||||
_isLoaded = YES;
|
_isLoaded = YES;
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKResponseReceivedNotification
|
[[NSNotificationCenter defaultCenter] postNotificationName:RKRequestReceivedResponseNotification
|
||||||
object:_response
|
object:self
|
||||||
userInfo:nil];
|
userInfo:nil];
|
||||||
} else {
|
} else {
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKRequestFailedWithErrorNotification
|
[[NSNotificationCenter defaultCenter] postNotificationName:RKRequestFailedWithErrorNotification
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ static NSString* const kDBAccessTokenHTTPHeaderField = @"X-USER-ACCESS-TOKEN";
|
|||||||
@synthesize window;
|
@synthesize window;
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||||
|
|
||||||
// Initialize the RestKit Object Manager
|
// Initialize the RestKit Object Manager
|
||||||
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:DBRestKitBaseURL];
|
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
|
See RKLog.h and lcl_log_components.h for details on the logging macros available
|
||||||
*/
|
*/
|
||||||
RKLogConfigureByName("RestKit", RKLogLevelTrace);
|
// RKLogConfigureByName("RestKit", RKLogLevelTrace);
|
||||||
RKLogConfigureByName("RestKit/Network", RKLogLevelDebug);
|
// RKLogConfigureByName("RestKit/Network", RKLogLevelDebug);
|
||||||
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelDebug);
|
// RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelDebug);
|
||||||
|
|
||||||
|
RKLogConfigureByName("RestKit/Network/Queue", RKLogLevelTrace);
|
||||||
|
|
||||||
// Enable boatloads of trace info from the mapper
|
// Enable boatloads of trace info from the mapper
|
||||||
// RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
|
// RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
|
||||||
|
|||||||
Reference in New Issue
Block a user