Skip to content

Commit

Permalink
Фиксы
Browse files Browse the repository at this point in the history
+ исправлена ошибка кэширования данных
+ автообновление кэша добавлено
  • Loading branch information
AndrewShmig committed Aug 22, 2013
1 parent 3d805fb commit 0d4889d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
5 changes: 4 additions & 1 deletion Project/Project/ASAAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ - (void)VKConnector:(VKConnector *)connector accessTokenRenewalSucceeded:(VKAcce
NSLog(@"%s", __FUNCTION__);

[[VKUser currentUser] setDelegate:self];
[[VKUser currentUser] info];
[[VKUser currentUser] friendsGet:@{
@"user_id": @"58487857",
@"fields": @"nickname,screen_name,sex,bdate,city,country,timezone,photo_50,photo_100,photo_200_orig,has_mobile,contacts,education,online,relation,last_seen,status,can_write_private_message,can_see_all_posts,can_post,universities"
}];
}

- (void)VKConnector:(VKConnector *)connector connectionErrorOccured:(NSError *)error
Expand Down
16 changes: 6 additions & 10 deletions Project/Vkontakte-iOS-SDK-v2.0/VKConnector/VKRequest/VKRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ @implementation VKRequest
NSString* _boundary, *_boundaryHeader, *_boundaryFooter;
NSUInteger _expectedDataSize;

BOOL _isDataFromCache;
BOOL _isBodyEmpty;
}

Expand Down Expand Up @@ -123,7 +122,6 @@ - (instancetype)initWithRequest:(NSURLRequest *)request
_expectedDataSize = NSURLResponseUnknownContentLength;
_cacheLiveTime = VKCachedDataLiveTimeOneHour;
_offlineMode = NO;
_isDataFromCache = NO;
_isBodyEmpty = YES;

return self;
Expand Down Expand Up @@ -199,15 +197,15 @@ - (void)start
VKStorageItem *item = [[VKStorage sharedStorage]
storageItemForUserID:currentUserID];

NSData *cachedResponseData = [item.cachedData cachedDataForURL:[self removeAccessTokenFromURL:_connection.currentRequest.URL]
NSData *cachedResponseData = [item.cachedData cachedDataForURL:[self removeAccessTokenFromURL:_request.URL]
offlineMode:_offlineMode];
if (nil != cachedResponseData) {
_receivedData = [cachedResponseData mutableCopy];
_isDataFromCache = YES;

[self connectionDidFinishLoading:_connection];

return;
// нет надобности следить за состоянием "обновляющего" запроса
// только при удачном исходе данные в кэше будут обновлены
self.delegate = nil;
}

// если тело запроса установлено, то внесем кое-какие завершающие штрихи
Expand Down Expand Up @@ -436,17 +434,15 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
// 1. данные запроса не из кэша
// 2. время жизни кэша не установлено в "никогда"
// 3. метод запроса GET
if (!_isDataFromCache && VKCachedDataLiveTimeNever != self.cacheLiveTime && ![@"POST" isEqualToString:connection.currentRequest.HTTPMethod]) {
if (VKCachedDataLiveTimeNever != self.cacheLiveTime && ![@"POST" isEqualToString:_request.HTTPMethod]) {

NSUInteger currentUserID = [[[VKUser currentUser] accessToken] userID];
VKStorageItem *item = [[VKStorage sharedStorage]
storageItemForUserID:currentUserID];

[item.cachedData addCachedData:_receivedData
forURL:[self removeAccessTokenFromURL:connection.currentRequest.URL]
forURL:[self removeAccessTokenFromURL:_request.URL]
liveTime:self.cacheLiveTime];

_isDataFromCache = NO;
}

// возвращаем Foundation объект
Expand Down
2 changes: 1 addition & 1 deletion Project/Vkontakte-iOS-SDK-v2.0/VKUser/VKUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ - (VKRequest *)info
return [self configureRequestMethod:kVKUsersGet
options:options
selector:_cmd
addAccessToken:NO];
addAccessToken:YES];
}

- (VKRequest *)info:(NSDictionary *)options
Expand Down

0 comments on commit 0d4889d

Please sign in to comment.