我以编程方式从通讯簿中检索电子邮件地址的方法似乎不再适用于 iOS 6 设备。它在 iOS 5 中工作,奇怪的是,仍然在 iOS 6 模拟器中工作。是否有一种以编程方式从用户通讯录中检索联系人的新方法?
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
self.contacts = [[NSMutableArray alloc] init];
int contactIndex = 0;
for (int i = 0; i < nPeople; i++) {
// Get the next address book record.
ABRecordRef record = CFArrayGetValueAtIndex(allPeople, i);
// Get array of email addresses from address book record.
ABMultiValueRef emailMultiValue = ABRecordCopyValue(record, kABPersonEmailProperty);
NSArray *emailArray = (__bridge_transfer NSArray *)ABMultiValueCopyArrayOfAllValues(emailMultiValue);
[self.contacts addObject:emailArray];
}
为了澄清,上面没有崩溃,它只是不返回任何结果。ABAddressBookCopyArrayOfAllPeople 为空。谢谢!