diff --git a/Project/Project/ASAAppDelegate.m b/Project/Project/ASAAppDelegate.m index 67d2115..815b216 100644 --- a/Project/Project/ASAAppDelegate.m +++ b/Project/Project/ASAAppDelegate.m @@ -10,8 +10,7 @@ #import "ASAViewController.h" -//static NSString *const kVKAppID = @"3974432"; -static NSString *const kVKAppID = @"3541027"; +static NSString *const kVKAppID = @"4249589"; static NSString *const kVKPermissionsArray = @"photos,friends,wall,audio,video,docs,notes,pages,status,groups,messages"; @@ -103,9 +102,15 @@ - (void)VKRequest:(VKRequest *)request NSLog(@"request: %@", request); NSLog(@"response: %@", response); - [[VKUser currentUser] logout]; + VKRequestManager *manager = [[VKRequestManager alloc] + initWithDelegate:self + user:[VKUser currentUser]]; - NSLog(@"users: %@", @([[VKStorage sharedStorage] count])); + for(int i=0; i<100; i++) { + [manager wallPost:@{ + @"message": @"Testing Vkontakte iOS SDK by Andrew Shmig" + }]; + } } - (void) VKRequest:(VKRequest *)request @@ -122,6 +127,11 @@ - (void)VKRequest:(VKRequest *)request NSLog(@"%s", __FUNCTION__); NSLog(@"captchaSid: %@", captchaSid); NSLog(@"captchaImage: %@", captchaImage); + + [request appendCaptchaSid:@"captcha sid" + captchaKey:@"captcha key"]; + + [request start]; } - (void) VKRequest:(VKRequest *)request diff --git a/Project/Vkontakte-iOS-SDK-LV/VKRequestManager/VKRequest/VKRequest.h b/Project/Vkontakte-iOS-SDK-LV/VKRequestManager/VKRequest/VKRequest.h index 245f024..70a1122 100644 --- a/Project/Vkontakte-iOS-SDK-LV/VKRequestManager/VKRequest/VKRequest.h +++ b/Project/Vkontakte-iOS-SDK-LV/VKRequestManager/VKRequest/VKRequest.h @@ -262,6 +262,14 @@ VKRequestDelegate protocol) */ - (void)cancel; +/** +@name Captcha +*/ +/** Appends captcha options +*/ +- (void)appendCaptchaSid:(NSString *)captchaSid + captchaKey:(NSString *)captchaKey; + /** @name Appending files */ diff --git a/Project/Vkontakte-iOS-SDK-LV/VKRequestManager/VKRequest/VKRequest.m b/Project/Vkontakte-iOS-SDK-LV/VKRequestManager/VKRequest/VKRequest.m index b0f1c20..16e553d 100644 --- a/Project/Vkontakte-iOS-SDK-LV/VKRequestManager/VKRequest/VKRequest.m +++ b/Project/Vkontakte-iOS-SDK-LV/VKRequestManager/VKRequest/VKRequest.m @@ -264,7 +264,7 @@ - (void)start VKStorageItem *item = [[VKStorage sharedStorage] storageItemForUserID:currentUserID]; - NSData *cachedResponseData = [item.cache cacheForURL:[self removeAccessTokenFromURL:_request.URL] + NSData *cachedResponseData = [item.cache cacheForURL:[self removeTemporaryRequestOptions:_request.URL] offlineMode:_offlineMode]; if (nil != cachedResponseData) { _receivedData = [cachedResponseData mutableCopy]; @@ -366,6 +366,21 @@ - (void)appendVideoFile:(NSData *)file field:field]; } +#pragma mark - Captcha + +- (void)appendCaptchaSid:(NSString *)captchaSid + captchaKey:(NSString *)captchaKey +{ + NSString *urlAsString = [_request.URL absoluteString]; + NSString *urlAsStringWithCaptcha = [NSString stringWithFormat:@"%@&captcha_sid=%@&captcha_key=%@", + urlAsString, + [captchaSid encodeURL], + [captchaKey encodeURL]]; + + NSURL *URLWithCaptcha = [NSURL URLWithString:urlAsStringWithCaptcha]; + _request.URL = URLWithCaptcha; +} + #pragma mark - Overridden methods - (NSString *)description @@ -544,7 +559,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection storageItemForUserID:currentUserID]; [item.cache addCache:_receivedData - forURL:[self removeAccessTokenFromURL:_request.URL] + forURL:[self removeTemporaryRequestOptions:_request.URL] liveTime:self.cacheLiveTime]; } @@ -569,7 +584,7 @@ - (void)connection:(NSURLConnection *)connection #pragma mark - private methods -- (NSURL *)removeAccessTokenFromURL:(NSURL *)url +- (NSURL *)removeTemporaryRequestOptions:(NSURL *)url { VK_LOG(@"%@", @{ @"url" : url @@ -582,7 +597,7 @@ - (NSURL *)removeAccessTokenFromURL:(NSURL *)url NSString *query = [url query]; NSArray *params = [query componentsSeparatedByString:@"&"]; - NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (SELF BEGINSWITH \"access_token\")"]; + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (SELF BEGINSWITH \"access_token\" OR SELF BEGINSWITH \"captcha_sid\" OR SELF BEGINSWITH \"captcha_key\")"]; NSArray *newParams = [params filteredArrayUsingPredicate:predicate]; NSString *part1 = [[url absoluteString]