ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
friend_info = [[NSMutableArray alloc]init];
//===================================================//
// 저장된 구조체를 돌면서 해당 데이터를 추출해 옵니다.
//===================================================//
for (int i = 0; i < nPeople ; i++) {
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
CFStringRef lastName = ABRecordCopyValue(ref, kABPersonLastNameProperty);
NSString *name = [NSString stringWithFormat:@"%@ %@", (lastName != nil) ? (NSString *)lastName : @"" ,(firstName != nil) ? (NSString *)firstName : @""];
if (name == nil) {
return;
}
// 이메일 리트를 구한다.
ABMultiValueRef emails = ABRecordCopyValue(ref, kABPersonEmailProperty);
// 이메일 리스트가 존재하지 않으면
if(ABMultiValueGetCount(emails) <= 0) { // the selected contact has no attached email address
[self dismissModalViewControllerAnimated:YES];
}
else{ //if(ABMultiValueGetCount(emails) == 1) { // the selected contact has exactly one email address
for(int i=0; i<ABMultiValueGetCount(emails); i++){
CFStringRef email = ABMultiValueCopyValueAtIndex(emails, i);
NSString *emailString = (NSString *) email;
//self.emailList.text = [self.emailList.text stringByAppendingString:[NSString stringWithFormat:@"%@ ", emailString]];
//NSLog(@"email = %@", emailString);
//이메일이 있는 사람들만 저장하도록 합니다.
if(emailString == nil){
}else {
NSDictionary *info = [[NSDictionary alloc] initWithObjectsAndKeys:
name, @"NAME", emailString, @"EMAIL", kNotSelectTableCell, @"CHECK", nil];
email_person_cnt++;
[friend_info addObject:info];
[info release];
}
[emailString release];
[self dismissModalViewControllerAnimated:YES];
}
}
ABMultiValueRef phones = ABRecordCopyValue(ref, kABPersonPhoneProperty);
if(ABMultiValueGetCount(phones) <= 0) { // the selected contact has no attached email address
[self dismissModalViewControllerAnimated:YES];
}
else{ //if(ABMultiValueGetCount(emails) == 1) { // the selected contact has exactly one email address
for(int i=0; i<ABMultiValueGetCount(phones); i++){
CFStringRef phone = ABMultiValueCopyValueAtIndex(phones, i);
NSString *phoneString = (NSString *) phone;
if(phoneString == nil){
}else {
NSDictionary *info = [[NSDictionary alloc] initWithObjectsAndKeys:
name, @"NAME", phoneString, @"EMAIL", kNotSelectTableCell, @"CHECK", nil];
email_person_cnt++;
[friend_info addObject:info];
[info release];
}
[phoneString release];
[self dismissModalViewControllerAnimated:YES];
}
}
}
CFRelease(allPeople);
더 자세히 알고싶으시면 댓글이나 방명록에 써주세요.
'Developer > iOS' 카테고리의 다른 글
[IPhone] TabBarController의 TabBar(hidden) 숨기기. (1) | 2011.01.18 |
---|---|
[IPhone] Twipic을 이용해서 이미지 업로드하기! (2) | 2011.01.12 |
[IPhone] SMS보내기 (1) | 2011.01.12 |
[IPhone]UIAlertView(경고창) 띄우는 방법과 경고창이 여러개일 때, 이벤트 구별하는 방법 (2) | 2011.01.12 |
[IPhone] zBar를 이용하여 바코드 인식하기. (0) | 2010.12.03 |