From 0d4889d8906ba6891a6bee8a8f98b8274b45fa7d Mon Sep 17 00:00:00 2001 From: AndrewShmig Date: Thu, 22 Aug 2013 16:33:17 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + исправлена ошибка кэширования данных + автообновление кэша добавлено --- Project/Project/ASAAppDelegate.m | 5 ++++- .../VKConnector/VKRequest/VKRequest.m | 16 ++++++---------- Project/Vkontakte-iOS-SDK-v2.0/VKUser/VKUser.m | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Project/Project/ASAAppDelegate.m b/Project/Project/ASAAppDelegate.m index 55e8c7d..df5675c 100644 --- a/Project/Project/ASAAppDelegate.m +++ b/Project/Project/ASAAppDelegate.m @@ -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 diff --git a/Project/Vkontakte-iOS-SDK-v2.0/VKConnector/VKRequest/VKRequest.m b/Project/Vkontakte-iOS-SDK-v2.0/VKConnector/VKRequest/VKRequest.m index 182034e..ccd01c5 100644 --- a/Project/Vkontakte-iOS-SDK-v2.0/VKConnector/VKRequest/VKRequest.m +++ b/Project/Vkontakte-iOS-SDK-v2.0/VKConnector/VKRequest/VKRequest.m @@ -48,7 +48,6 @@ @implementation VKRequest NSString* _boundary, *_boundaryHeader, *_boundaryFooter; NSUInteger _expectedDataSize; - BOOL _isDataFromCache; BOOL _isBodyEmpty; } @@ -123,7 +122,6 @@ - (instancetype)initWithRequest:(NSURLRequest *)request _expectedDataSize = NSURLResponseUnknownContentLength; _cacheLiveTime = VKCachedDataLiveTimeOneHour; _offlineMode = NO; - _isDataFromCache = NO; _isBodyEmpty = YES; return self; @@ -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; } // если тело запроса установлено, то внесем кое-какие завершающие штрихи @@ -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 объект diff --git a/Project/Vkontakte-iOS-SDK-v2.0/VKUser/VKUser.m b/Project/Vkontakte-iOS-SDK-v2.0/VKUser/VKUser.m index 6a3b44e..ba595d1 100644 --- a/Project/Vkontakte-iOS-SDK-v2.0/VKUser/VKUser.m +++ b/Project/Vkontakte-iOS-SDK-v2.0/VKUser/VKUser.m @@ -123,7 +123,7 @@ - (VKRequest *)info return [self configureRequestMethod:kVKUsersGet options:options selector:_cmd - addAccessToken:NO]; + addAccessToken:YES]; } - (VKRequest *)info:(NSDictionary *)options