我從地址簿中以編程方式檢索電子郵件地址的方法似乎不再適用於iOS 6設備。它在iOS 5中工作,奇怪的是,仍然在iOS 6模擬器中工作。有沒有新的方式來編程檢索用戶的地址簿中的聯繫人?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爲空。謝謝!
是的,你說得對。需要使用ABAddressBookRequestAccessWithCompletion()。我如何檢查此方法是否存在(對於
Keller