我对xcode编程很天真。我需要在变量上加载iPhone PhoneBook中的所有联系人。
你能不能给我一些图书馆或类似的东西。任何示例代码都会非常值得注意。
期待回应。:))
提前致谢!! ..... :)。
答案 0 :(得分:0)
经过长时间的战斗后,我发现以下代码正常工作
self.dataSource = [[NSMutableArray alloc]init]; // dataSouce is delared in .h file
ABAddressBookRef addressBook = ABAddressBookCreate();
NSMutableArray *allPeople = (NSMutableArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
int nPeople = ABAddressBookGetPersonCount(addressBook);
for(int i=0; i < nPeople; i++ ){
ABRecordRef person = [allPeople objectAtIndex:i];
NSString *name = @"";
if(ABRecordCopyValue(person, kABPersonFirstNameProperty) != NULL)
name = [[NSString stringWithFormat:@"%@", ABRecordCopyValue(person, kABPersonFirstNameProperty)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
[dataSource addObject: name];
}