Skip to content

UIViewController for working with VK captcha using Vkontakte iOS SDK

Notifications You must be signed in to change notification settings

nileshrathod41/vk-sdk-captcha-vc

Repository files navigation

#Vkontakte iOS SDK UIViewController for captcha example

UIViewController for working with VK captcha using Vkontakte iOS SDK. Earlier it could be realized via UIAlertView, but in iOS 7 adding subviews in UIAlertView was deprecated.

Vkontakte iOS SDK repo.

#Code Example RootViewController.h

#import "VKCaptchaViewController.h"
@interface RootViewController : UIViewController <VKConnectorDelegate, VKRequestDelegate, VKCaptchaVCProtocol> {
	NSString *captchaSessionId;
}

RootViewController.m

#pragma mark - VKConnectorDelegate

- (void)VKRequest:(VKRequest *)request captchaSid:(NSString *)captchaSid captchaImage:(NSString *)captchaImage {
	
	if ( captchaSessionId == nil ) {
		captchaSessionId = captchaSid;
		[self getCaptchaWithUrl:captchaImage];
	}
}

- (void)getCaptchaWithUrl:(NSString *)captcha_img {
	
	VKCaptchaViewController *captchaView = [[VKCaptchaViewController alloc] init];
	captchaView.delegate = self;
		
	[self presentViewController:captchaView animated:YES completion:^() {
		captchaView.captchaImg.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:captcha_img]]];
	}];
}

- (void)captchaEnteredWithValue:(NSString *)captchaValue {
	/* your code, for example: */
	VKRequestManager *rm = [[VKRequestManager alloc] initWithDelegate:self user:[VKUser currentUser]];
	rm wallPost:@{
	   @"owner_id": @([VKUser currentUser].accessToken.userID),
	   @"message" : @"I wrestled this captcha!",
	   @"captcha_sid" : captchaSessionId,
	   @"captcha_key" : captchaText
	}];
}

#Screenshot UIViewController for captcha example

About

UIViewController for working with VK captcha using Vkontakte iOS SDK

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published