2012-01-24 65 views

回答

4

是的,這是可能的。下面有一個簡單的代碼片段,做的工作:

ABAddressBookRef addressBook = ABAddressBookCreate(); 

CFArrayRef allPeopleRef = ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, nil, kABPersonSortByFirstName); 

CFIndex nPeople = ABAddressBookGetPersonCount(addressBook); 


for(int i = 0 ; i < nPeople ; i++) { 
    ABRecordRef ref = CFArrayGetValueAtIndex(allPeopleRef, i); 
    CFStringRef tmpStringRef = ABRecordCopyValue(ref, kABPersonFirstNameProperty); 
    NSLog(@"FirstName: %@", (NSString *)tmpStringRef); 
    CFRelease(tmpStringRef); 
} 

//clean up memory 
CFRelease(allPeopleRef); 
CFRelease(addressBook); 

欲瞭解更多詳情,請參閱蘋果開發者文檔here

+0

此代碼可以幫助我節省很多時間..謝謝你+1 – Vidhyanand

相關問題