CFArrayAppendValue崩溃:EXC_BREAKPOINT(SIGTRAP)

时间:2013-06-23 16:52:51

标签: ios crash

我正在分析我的应用的崩溃报告。看来我的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不存在?)回调方法使用错了吗?

感谢您的帮助, 约翰约翰

1 个答案:

答案 0 :(得分: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);
    }
}
相关问题