diff --git a/src/FBRequest.h b/src/FBRequest.h index 7205c10bf9..c1143493b9 100644 --- a/src/FBRequest.h +++ b/src/FBRequest.h @@ -39,6 +39,7 @@ typedef NSUInteger FBRequestState; NSMutableData* _responseText; FBRequestState _state; NSError* _error; + BOOL _sessionDidExpire; } @@ -64,6 +65,7 @@ typedef NSUInteger FBRequestState; @property(nonatomic,retain) NSURLConnection* connection; @property(nonatomic,retain) NSMutableData* responseText; @property(nonatomic,readonly) FBRequestState state; +@property(nonatomic,readonly) BOOL sessionDidExpire; /** * Error returned by the server in case of request's failure (or nil otherwise). diff --git a/src/FBRequest.m b/src/FBRequest.m index 593d3160dd..eb1b8104eb 100644 --- a/src/FBRequest.m +++ b/src/FBRequest.m @@ -23,6 +23,7 @@ static NSString* kUserAgent = @"FacebookConnect"; static NSString* kStringBoundary = @"3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f"; static const int kGeneralErrorCode = 10000; +static const int kRESTAPIAccessTokenErrorCode = 190; static const NSTimeInterval kTimeoutInterval = 180.0; @@ -30,6 +31,7 @@ @interface FBRequest () @property (nonatomic,readwrite) FBRequestState state; +@property (nonatomic,readwrite) BOOL sessionDidExpire; @end @implementation FBRequest @@ -41,6 +43,7 @@ @implementation FBRequest connection = _connection, responseText = _responseText, state = _state, + sessionDidExpire = _sessionDidExpire, error = _error; ////////////////////////////////////////////////////////////////////////////////////////////////// // class public @@ -239,10 +242,12 @@ - (id)parseJsonResponse:(NSData *)data error:(NSError **)error { * fails with error */ - (void)failWithError:(NSError *)error { + if ([error code] == kRESTAPIAccessTokenErrorCode) { + self.sessionDidExpire = YES; + } if ([_delegate respondsToSelector:@selector(request:didFailWithError:)]) { [_delegate request:self didFailWithError:error]; } - self.state = kFBRequestStateError; } /* @@ -313,6 +318,7 @@ - (void)connect { _connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; self.state = kFBRequestStateLoading; + self.sessionDidExpire = NO; } /** @@ -355,10 +361,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection { self.responseText = nil; self.connection = nil; - - if (self.state != kFBRequestStateError) { - self.state = kFBRequestStateComplete; - } + self.state = kFBRequestStateComplete; } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { @@ -366,8 +369,7 @@ - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err self.responseText = nil; self.connection = nil; - - self.state = kFBRequestStateError; + self.state = kFBRequestStateComplete; } @end diff --git a/src/Facebook.m b/src/Facebook.m index 4380e84afa..e765ec5e86 100644 --- a/src/Facebook.m +++ b/src/Facebook.m @@ -182,13 +182,13 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N if (context == finishedContext) { FBRequest* _request = (FBRequest*)object; FBRequestState requestState = [_request state]; - if (requestState == kFBRequestStateError) { - [self invalidateSession]; - if ([self.sessionDelegate respondsToSelector:@selector(fbSessionInvalidated)]) { - [self.sessionDelegate fbSessionInvalidated]; + if (requestState == kFBRequestStateComplete) { + if ([_request sessionDidExpire]) { + [self invalidateSession]; + if ([self.sessionDelegate respondsToSelector:@selector(fbSessionInvalidated)]) { + [self.sessionDelegate fbSessionInvalidated]; + } } - } - if (requestState == kFBRequestStateComplete || requestState == kFBRequestStateError) { [_request removeObserver:self forKeyPath:requestFinishedKeyPath]; [_requests removeObject:_request]; }