gpt4 book ai didi

xcode - 为什么此联系人总是显示为 Nil/null,即使我设置了它或添加了电子邮件?

转载 作者:行者123 更新时间:2023-12-02 00:15:19 26 4
gpt4 key购买 nike

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

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

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

最佳答案

明白了...看起来像是我应该预料到的某种 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);

在第二个 View Controller 中,我传递了 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);

修复 ... 在第二个 View Controller 中重复:

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

宾果问题解决了!!

关于xcode - 为什么此联系人总是显示为 Nil/null,即使我设置了它或添加了电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13453572/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com