1

我正在分析我的应用程序的崩溃报告。看来我对 CFArrayAppendValue 有疑问。

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000000000defe
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   CoreFoundation                  0x330f8268 __CFTypeCollectionRetain
1   CoreFoundation                  0x330619ca _CFArrayReplaceValues
2   CoreFoundation                  0x330618ba CFArrayAppendValue

我试图了解用户如何导致此崩溃,但这对我来说并不明显。使用的代码非常简单:

CFMutableArrayRef CFgroupMemberMutable = CFArrayCreateMutable (NULL,0,&kCFTypeArrayCallBacks);
for (id key in [dataManager getSpecificGroupMembers:groupID]){
    ABRecordRef thisContact = ABAddressBookGetPersonWithRecordID (myAddressBook, [key intValue]);
    CFArrayAppendValue (CFgroupMemberMutable,thisContact);
}

是因为我尝试附加一个 NULL 值吗?(ABRecordRef 不存在?)是不是回调方法用错了?

感谢您的帮助,约翰·约翰

4

1 回答 1

0

是的,如果您尝试使用 CFArrayAppendValue() 附加 NULL 值,则会引发异常并且您将获得 EXC_BREAKPOINT。您的示例中使用的默认回调看起来是正确的。

如果没有找到通讯录中的记录,ABAddressBookGetPersonWithRecordID() 可能会返回 NULL,因此您必须检查 NULL,这里是更新的代码:

CFMutableArrayRef CFgroupMemberMutable = CFArrayCreateMutable (NULL,0,&kCFTypeArrayCallBacks);
for (id key in [dataManager getSpecificGroupMembers:groupID]){
    ABRecordRef thisContact = ABAddressBookGetPersonWithRecordID (myAddressBook, [key intValue]);
    if (thisContact)
    {
        CFArrayAppendValue (CFgroupMemberMutable,thisContact);
    }
}
于 2014-05-22T19:27:12.727 回答