ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
for(int i = 0;i<ABAddressBookGetPersonCount(addressBook);i++)
{
ABRecordRef ref = CFArrayGetValueAtIndex(people, i);
// Get First name, Last name, Prefix, Suffix, Job title
NSString *firstName = (NSString *)ABRecordCopyValue(ref,kABPersonFirstNameProperty);
NSString *lastName = (NSString *)ABRecordCopyValue(ref,kABPersonLastNameProperty);
if(firstName == nil)
firstName = @"";
if(lastName == nil)
lastName = @"";
NSString *fullName = [NSString stringWithFormat:@"%@%@", lastName, firstName];
NSMutableDictionary *tmpDic = [[NSMutableDictionary alloc] init];
if(fullName != nil)
[tmpDic setObject:fullName forKey:@"name"];
ABMultiValueRef phones = ABRecordCopyValue(ref, kABPersonPhoneProperty);
for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++)
{
CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, j);
NSString *phoneLabel =(NSString*) ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(phones, j));
if([phoneLabel isEqualToString:@"mobile"]) {
NSString *phoneNumber = (NSString *)phoneNumberRef;
if(phoneNumber != nil)
[tmpDic setObject:phoneNumber forKey:@"mobile"];
}
}
[self.arr_contact addObject:tmpDic];
[self.arr_tmpContact addObject:tmpDic];
'Developer > iOS' 카테고리의 다른 글
[iOS]NSTimer 사용하기 (타이머) (0) | 2015.08.31 |
---|---|
[iOS]숫자 세자리마다 콤마 (,) 추가하기 (0) | 2013.08.22 |
[iOS]네비게이션 숨기고 보이게하기 (0) | 2013.06.11 |
[iOS]Xcode Terminal로 commit하기. (1) | 2013.06.04 |
[iOS]원(circle draw) 그리기 (0) | 2013.06.04 |