1
我想在不使用ABPeoplePickerNavigationController的情況下獲取設備上的聯繫人,可能在objective-c中?獲取沒有ABPeoplePickerNavigationController的聯繫人
我想在不使用ABPeoplePickerNavigationController的情況下獲取設備上的聯繫人,可能在objective-c中?獲取沒有ABPeoplePickerNavigationController的聯繫人
是的,這是可能的。下面有一個簡單的代碼片段,做的工作:
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。
它是。請參閱AddresBook編程指南。 Direct interaction section。
此代碼可以幫助我節省很多時間..謝謝你+1 – Vidhyanand