2013-06-23 131 views
1

我正在分析我的应用的崩溃报告。看起来我有CFArrayAppendValue问题。CFArrayAppendValue崩溃:EXC_BREAKPOINT(SIGTRAP)

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不存在?)使用的回调方法是否错误?

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

回答

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