地址簿崩溃,只与一些联系人

问题描述:

我的应用程序崩溃,这是一个AddressBook API出现的问题,它只发生在一些联系人。地址簿崩溃,只与一些联系人

这里是日志:

Exception Type: EXC_BREAKPOINT (SIGTRAP) 
Exception Codes: 0x00000102, 0x316ebd38 
Crashed Thread: 0 

Thread 0 Crashed: 
0 CoreFoundation     0x00001cfe CFRetain + 90 
1 AddressBook      0x00004b2c ABCMultiValueCopyValueAtIndex + 28 
2 AddressBook      0x0001066a ABMultiValueCopyValueAtIndex + 2 
3 Call Monitor      0x00003824 -[CallAppDelegate peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:] (AppDelegate.m:408) 
4 AddressBookUI      0x00032cfc -[ABPeoplePickerNavigationController personViewController:shouldPerformDefaultActionForPerson:property:identifier:withMemberCell:] + 152 
5 AddressBookUI      0x0003b8ce -[ABPersonViewControllerHelper personTableViewDataSource:selectedPropertyAtIndex:inPropertyGroup:withMemberCell:forEditing:] + 222 
6 AddressBookUI      0x0004a17c -[ABPersonTableViewDataSource valueAtIndex:selectedForPropertyGroup:withMemberCell:forEditing:] + 40 
7 AddressBookUI      0x00048c00 -[ABPersonTableViewDataSource tableView:didSelectRowAtIndexPath:] + 316 
8 UIKit        0x00091f40 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 656 
9 UIKit        0x0009db40 -[UITableView _userSelectRowAtIndexPath:] + 124 
10 Foundation      0x00086c86 __NSFireDelayedPerform + 362 
11 CoreFoundation     0x00071a54 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8 
12 CoreFoundation     0x00073ede __CFRunLoopDoTimer + 854 
13 CoreFoundation     0x0007485e __CFRunLoopRun + 1082 
14 CoreFoundation     0x0001d8e4 CFRunLoopRunSpecific + 224 
15 CoreFoundation     0x0001d7ec CFRunLoopRunInMode + 52 
16 GraphicsServices     0x000036e8 GSEventRunModal + 108 
17 GraphicsServices     0x00003794 GSEventRun + 56 
18 UIKit        0x000062a0 -[UIApplication _run] + 396 
19 UIKit        0x00004e10 UIApplicationMain + 664 
20 Call Monitor      0x000028e8 main (main.m:14) 
21 Call Monitor      0x000028b8 start + 32 

这是推动我疯了,因为它仅与接触的隔离数量发生。

任何帮助将不胜感激。

这里是被请求的代码,非常感谢你非常多的帮助:

(这是从哪儿我认为错误发生的方法的提取物)

奇怪的是,它只有具有一定的接触情况,和删除联系人,然后创建一个新的解决了这个问题...

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person 
           property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier 

    NSString* firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); 
    NSString* lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty); 
    NSNumber* record = [NSNumber numberWithInt:ABRecordGetRecordID(person)]; 
    if(lastName!=nil){ 
     name=[NSString stringWithFormat:@"%@ %@",firstName,lastName]; 
    } 
    else { 
     name=firstName; 
    } 

     ABMultiValueRef phone = ABRecordCopyValue(person, property); 
     NSString *value =(NSString *)ABMultiValueCopyValueAtIndex(phone, identifier); 
     NSString *label =(NSString *)ABMultiValueCopyLabelAtIndex(phone, identifier); 
     NSMutableArray *tempArray=[[NSMutableArray alloc] initWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"MainArray"]]; 
     NSDictionary *stringDictionary = [NSDictionary dictionaryWithObjectsAndKeys:name, kLabelKey, value, kNumberKey,label, kNumberLabelKey,record, kReferenceKey, nil]; 
     [tempArray addObject:stringDictionary]; 
     NSArray *mainArray = [NSArray arrayWithArray:tempArray]; 
     [[NSUserDefaults standardUserDefaults] setObject:mainArray forKey:@"MainArray"]; 
+0

什么是您创建崩溃的输入?这是否总是会发生一些特定的联系?什么是错误信息? – vodkhang 2010-09-29 02:43:31

+1

包含来自' - [CallAppDelegate peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:]'的代码会非常有用,尤其是AppDelegate.m第408行附近的代码。 – 2010-09-29 04:14:29

+0

我已经在代码中包含了我认为发生错误的代码,建议用@try @catch包装整个提取文件? – Zebs 2010-10-01 04:53:07

要有人遇到了类似的问题:

ABMultiValueCopyValueAtIndex与标识符而不是索引:从事实,我是用来到

我的错误。

您必须致电ABMultiValueGetIndexForIdentifier,然后在ABMultiValueCopyValueAtIndex上使用该索引。

底线是Identifier!=index

我会确保你真的处理有效的多值记录类型。

if (ABMultiValueGetPropertyType(phone) != kABInvalidPropertyType) { 
    // Do work here. 
} 

其实,确保它确实是一个字符串可能会更安全。

if (ABMultiValueGetPropertyType(phone) == kABMultiStringPropertyType) { 
    // Do work here. 
} 

我不知道为什么不会这样。也许你有损坏的联系人条目?或者,也许有时电话号码不是多值类型?

而不是使用

ABMultiValueCopyValueAtIndex(multiValue, identifier);

其中Zebs指出以上,使用...

ABMultiValueCopyValueAtIndex(multiValue, ABMultiValueGetIndexForIdentifier(multiValue, identifier));