-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathXSSkypeContact.m
More file actions
84 lines (67 loc) · 2.21 KB
/
Copy pathXSSkypeContact.m
File metadata and controls
84 lines (67 loc) · 2.21 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// XSSkypeContact.m
// SkypeToAddressBook
//
// Created by Xavi Aracil on 18/08/10.
// Copyright 2010 xaracSoft (Xavi Aracil Diaz). All rights reserved.
//
#import "XSSkypeContact.h"
#import <AddressBook/AddressBook.h>
@implementation XSSkypeContact
@synthesize skype, delegate;
-(void) requestContacts {
// load contacts from Skype
// -> SEARCH FRIENDS
// <- USERS tim, joe, mike
XSSkype *skypeProxy = [[XSSkype alloc] initWithAppName:@"SkypeToAddressBook"];
skypeProxy.delegate = self;
self.skype = skypeProxy;
[skype connect];
[skypeProxy release];
}
- (void)dealloc {
[skype release];
[delegate release];
[super dealloc];
}
#pragma mark -
#pragma mark XSSkypeDelegate methods
-(void) skypeDidConnect {
[skype sendCommand:@"SEARCH FRIENDS" responder:self];
}
-(void) skypeDidFailConnect {
if ([delegate respondsToSelector:@selector(skypeFailToFetchContacts)]) {
[delegate performSelector:@selector(skypeFailToFetchContacts)];
}
}
-(void) skypeIsNotInstalled {
if ([delegate respondsToSelector:@selector(skypeIsNotInstalled)]) {
[delegate performSelector:@selector(skypeIsNotInstalled)];
}
}
#pragma mark -
#pragma mark XSSkypeResponder methods
-(void) response:(NSString *) response {
NSMutableArray *result = [NSMutableArray array];
NSScanner *theScanner = [NSScanner scannerWithString:response];
NSCharacterSet *characterSet = [NSCharacterSet whitespaceCharacterSet];
if ([theScanner isAtEnd] == NO) {
[theScanner scanString:kSkypeUsers intoString:NULL];
NSString *skypeContact;
while ([theScanner isAtEnd] == NO) {
[theScanner scanUpToCharactersFromSet:characterSet intoString:&skypeContact];
// remove last ","
if ([skypeContact hasSuffix:@","]) {
NSMutableString *mutableString = [NSMutableString stringWithString:skypeContact];
[mutableString deleteCharactersInRange:NSMakeRange([mutableString length] -1, 1)];
[result addObject:mutableString];
} else {
[result addObject:skypeContact];
}
}
}
if ([delegate respondsToSelector:@selector(contactsAvailable:)]) {
[delegate performSelector:@selector(contactsAvailable:) withObject:result];
}
}
@end