Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] webmail now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as Plain Text by registered user 4eJLoBeK ( 8 years ago )
#define VK_APP_ID @"5183098"

NSArray *scope;

-viewDidLoad {
    scope = @[ VK_PER_FRIENDS, VK_PER_WALL, VK_PER_AUDIO, VK_PER_PHOTOS, VK_PER_NOHTTPS, VK_PER_EMAIL, VK_PER_MESSAGES ];
    [[VKSdk initializeWithAppId:VK_APP_ID] registerDelegate:self];
    [[VKSdk instance] setUiDelegate:self];
    [VKSdk wakeUpSession:scope completeBlock:^(VKAuthorizationState state, NSError *error) {
      if (state == VKAuthorizationAuthorized) {
          [self startWorking];
      } else if (error) {
          [[[UIAlertView alloc] initWithTitle:nil message:[error description] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil] show];
      }
    }];
}
#pragma mark - VK SDK Delegate Methods

- (void)vkSdkAccessAuthorizationFinishedWithResult:(VKAuthorizationResult *)result {
    if (result.token) {
        [self startWorking];
    } else if (result.error) {
        [[[UIAlertView alloc] initWithTitle:nil message:[NSString stringWithFormat:@"Access denied\n%@", result.error] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil] show];
    }
    NSLog (@"id = %@ name = %@ surname = %@", result.user.id, result.user.first_name, result.user.last_name);
}

- (void)vkSdkUserAuthorizationFailed {
}

- (void)vkSdkNeedCaptchaEnter:(VKError *)captchaError {
}

- (void)vkSdkShouldPresentViewController:(UIViewController *)controller {

    [self presentViewController:controller animated:YES completion:nil];
}

#pragma mark - Actions

- (IBAction)loginVK:(id)sender {

    [VKSdk authorize:scope];
}

 

Revise this Paste

Your Name: Code Language: