为什么这个联系人总是以Nil / null出现,即使我设置它或添加电子邮件?

时间:2012-11-19 12:13:15

标签: xcode abaddressbook

在iOS 6中,此代码始终为Nil提供NSLog,但第一个始终提供正确的复合名称。因此我知道我可以访问地址簿,如果我在addressbook中更改名称,代码会记录正确的复合名称。无论我投放了多少封电子邮件,联系人ABMultiValueGetCount始终为Nil。这是为什么?

ABRecordRef person = (__bridge ABRecordRef)[addressBookArray objectAtIndex:x];

NSLog(@"%@ -", ABRecordCopyCompositeName(person));
NSLog(@"%ld -", ABMultiValueGetCount(ABRecordCopyValue(person, kABPersonEmailProperty)));

2 个答案:

答案 0 :(得分:2)

得到它......看起来像我应该预期的某种managedObjectContext条件......

在一个View Controller中,我这样做了:

ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
addressBookArray = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
// Prsented info on the user name, but not on the Emails
CFRelease(addressBook);

在第二个视图控制器中,我传递了addressBookArray以尝试保存一些周期然后执行此操作:

ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
// Successfully accessed name properties (suspect they were chached some where ?
// Unsuccsfully accessed email properties (they have never been accessed so no chache and I get Null
CFRelease(addressBook);

修复...在secondviewController中重复:

addressBookArray = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);

Bingo问题解决了!!

答案 1 :(得分:1)

请检查以下链接。那些可以解决你的问题。在ios6中,苹果已经改变了地址簿的许可。

App crashed in iOS 6 when user changes Contacts access permissions

iOS 6 Address Book not working?