3

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

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

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

2 回答 2

2

明白了...看起来像是我应该预料到的某种 managedObjectContext 条件...

在一个视图控制器中,我这样做了:

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);

宾果问题解决了!!

于 2012-11-20T12:26:55.907 回答
1

请检查以下链接。这些可能会解决您的问题。在ios6苹果已经改变了通讯录的权限。

当用户更改联系人访问权限时,应用程序在 iOS 6 中崩溃

iOS 6 地址簿不工作?

于 2012-11-19T12:52:16.630 回答