아이폰어플개발정보2010. 6. 24. 11:39
email을 이용해서 주소록에서 정보를 가져오는 방법

by alex 10. 3월 2009 07:54


 //Also you need to include AddressBook.framework

#import

#import

#import

[contactList removeAllObjects];

 
// open the default address book.

ABAddressBookRef m_addressbook = ABAddressBookCreate();

if (!m_addressbook) {

    NSLog(@"opening address book");

}

 
// can be cast to NSArray, toll-free

CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);

CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);

 
// CFStrings can be cast to NSString!

 
for (int i=0;i < nPeople;i++) {

 MContact *contact = [[MContact alloc] init];

  
 ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);

 CFStringRef firstName, lastName;

 firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);

 lastName  = ABRecordCopyValue(ref, kABPersonLastNameProperty);

 contact.name = [NSString stringWithFormat:@"%@ %@", firstName, lastName];

 
 ABMutableMultiValueRef eMail  = ABRecordCopyValue(ref, kABPersonEmailProperty);

 if(ABMultiValueGetCount(eMail) > 0) {

  contact.email =  (NSString *)ABMultiValueCopyValueAtIndex(eMail, 0);

  [contactList addObject:contact];

 }

  
 CFRelease(ref);

 CFRelease(firstName);

 CFRelease(lastName);

  
  
}



출처 : http://blog.naver.com/PostView.nhn?blogId=amoros21&logNo=140107111333
Posted by 오늘마감

댓글을 달아 주세요