为什么这个联系人总是显示为 Nil / null,即使我设置它或添加电子邮件也是如此



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

ABRecordRef person = (__bridge ABRecordRef)[addressBookArray objectAtIndex:x];
NSLog(@"%@ -", ABRecordCopyCompositeName(person));
NSLog(@"%ld -", ABMultiValueGetCount(ABRecordCopyValue(person, kABPersonEmailProperty)));

知道了...看起来像我应该预料到的某种托管对象上下文条件......

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

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

修复...在第二个视图中,重复:

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

宾果游戏问题解决了!!

请查看以下链接。这些可能会解决您的问题。在ios6中,苹果已经更改了地址簿的权限。

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

iOS 6地址簿不起作用?

最新更新