import Foundation Foundation class VKMAppDelegate class VKUser interfa

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#import <Foundation/Foundation.h>
@class VKMAppDelegate;
@class VKUser;
@interface VKMConnector : NSObject
{
VKMAppDelegate *appDelegate;
}
+ (instancetype)sharedVKMConnector;
- (void)getInformationAboutUser:(void(^) (VKUser *user)) getInfo;
- (void)getInformationAboutUserById:(NSString *)userID andExecute:(void (^)(VKUser *))getInfo;
- (void)getArrayOfFriends:(void(^) (NSArray *friends)) getFriends;
- (void)getUsersDialogs:(void(^) (NSArray *dialogs)) getDialogs;
@end
@implementation VKMConnector
+ (instancetype)sharedVKMConnector
{
static VKMConnector *_sharedVKMConnector = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedVKMConnector = [[VKMConnector alloc] init];
});
return _sharedVKMConnector;
}
- (void)getInformationAboutUser:(void(^) (VKUser *user)) getInfo
{
VKRequest *request = [[VKApi users] get:@{VK_API_FIELDS: @"id, first_name, last_name, sex, bdate, city, country, photo_200, online, online_mobile, status"}];
[request executeWithResultBlock:^(VKResponse *response) {
if ([response.json isKindOfClass:[NSArray class]]) {
NSArray *respArray = response.json;
if (respArray.count == 1 && [[respArray firstObject] isKindOfClass: NSDictionary.class]) {
NSDictionary *userResp = [respArray firstObject];
VKUser *user = [[VKUser alloc] initWithDictionary:userResp];
getInfo(user);
}
}
} errorBlock:^(NSError *error) {
NSLog(@"%@", error);
}];
}
@end