RKResponse should start loading on didReceiveData: or didSendBodyData, whichever is called first.

This prevents didSendData RKRequestDelegate method from being called before didStartLoading.

Remove goOffline and goOnline support from RKObjectManager. This did not work in the current implementation.
This commit is contained in:
Jeremy Ellison
2011-01-12 13:20:26 -05:00
parent a4e7e60467
commit 634185f48a
3 changed files with 14 additions and 35 deletions

View File

@@ -69,14 +69,17 @@
}
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
- (void)ensureDidStartLoading {
if (NO == _loading) {
_loading = YES;
if ([[_request delegate] respondsToSelector:@selector(requestDidStartLoad:)]) {
[[_request delegate] requestDidStartLoad:_request];
}
}
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[self ensureDidStartLoading];
[_body appendData:data];
}
@@ -94,6 +97,8 @@
}
- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite {
[self ensureDidStartLoading];
if ([[_request delegate] respondsToSelector:@selector(request:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:)]) {
[[_request delegate] request:_request didSendBodyData:bytesWritten totalBytesWritten:totalBytesWritten totalBytesExpectedToWrite:totalBytesExpectedToWrite];
}

View File

@@ -32,7 +32,6 @@ typedef enum {
NSObject<RKRouter>* _router;
RKManagedObjectStore* _objectStore;
RKObjectManagerOnlineState _onlineState;
BOOL _onlineStateForced;
}
/**
@@ -75,16 +74,6 @@ typedef enum {
*/
@property (nonatomic, retain) RKClient* client;
/**
* Puts the manager into offline mode. Requests will not be sent.
*/
- (void)goOffline;
/**
* Puts the manager into online mode. Requests will be sent.
*/
- (void)goOnline;
/**
* True when we are in online mode
*/

View File

@@ -33,7 +33,6 @@ static RKObjectManager* sharedManager = nil;
_client = [[RKClient clientWithBaseURL:baseURL] retain];
self.format = RKMappingFormatJSON;
_onlineState = RKObjectManagerOnlineStateUndetermined;
_onlineStateForced = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:RKReachabilityStateChangedNotification
@@ -85,18 +84,6 @@ static RKObjectManager* sharedManager = nil;
[super dealloc];
}
- (void)goOffline {
_onlineState = RKObjectManagerOnlineStateDisconnected;
_onlineStateForced = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:RKDidEnterOfflineModeNotification object:self];
}
- (void)goOnline {
_onlineState = RKObjectManagerOnlineStateConnected;
_onlineStateForced = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:RKDidEnterOnlineModeNotification object:self];
}
- (BOOL)isOnline {
return (_onlineState == RKObjectManagerOnlineStateConnected);
}
@@ -106,16 +93,14 @@ static RKObjectManager* sharedManager = nil;
}
- (void)reachabilityChanged:(NSNotification*)notification {
if (!_onlineStateForced) {
BOOL isHostReachable = [self.client.baseURLReachabilityObserver isNetworkReachable];
_onlineState = isHostReachable ? RKObjectManagerOnlineStateConnected : RKObjectManagerOnlineStateDisconnected;
if (isHostReachable) {
[[NSNotificationCenter defaultCenter] postNotificationName:RKDidEnterOnlineModeNotification object:self];
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:RKDidEnterOfflineModeNotification object:self];
}
BOOL isHostReachable = [self.client.baseURLReachabilityObserver isNetworkReachable];
_onlineState = isHostReachable ? RKObjectManagerOnlineStateConnected : RKObjectManagerOnlineStateDisconnected;
if (isHostReachable) {
[[NSNotificationCenter defaultCenter] postNotificationName:RKDidEnterOnlineModeNotification object:self];
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:RKDidEnterOfflineModeNotification object:self];
}
}