2013-06-23 72 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); 
    } 
}