2010-09-29 20 views
6

Lỗi ứng dụng của tôi, đó là sự cố phát sinh từ API AddressBook, nó chỉ xảy ra với một số liên hệ.AddressBook Crash, chỉ với một số liên hệ

Đây là nhật ký:

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 

này được lái xe cho tôi điên, vì nó chỉ xảy ra với một số cô lập địa chỉ liên lạc.

Mọi trợ giúp sẽ được đánh giá cao.

Đây là mã đã được yêu cầu, cảm ơn bạn rất rất nhiều vì sự giúp đỡ của bạn:

(Đây là một chiết xuất từ ​​phương pháp mà tôi nghĩ rằng lỗi xảy ra)

Điều kỳ lạ là nó chỉ xảy ra với một số liên hệ nhất định và xóa địa chỉ liên hệ, sau đó tạo địa chỉ liên hệ mới giải quyết vấn đề ...

- (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

đầu vào mà bạn tạo ra các vụ tai nạn là gì? Điều này có luôn xảy ra đối với một số liên hệ cụ thể không? Thông báo lỗi là gì? – vodkhang

+1

Bao gồm mã từ '- [CallAppDelegate peoplePickerNavigationController: shouldContinueAfterSelectingPerson: property: identifier:]' sẽ rất hữu ích, đặc biệt là mã xung quanh dòng 408 của AppDelegate.m. –

+0

Tôi đã bao gồm mã nơi tôi nghĩ rằng lỗi xảy ra, nó sẽ được khuyến khích để quấn toàn bộ trích xuất với @try @catch? – Zebs

Trả lời

12

Để ai gặp một vấn đề tương tự:

lỗi của tôi đến từ thực tế là tôi đã sử dụng:

ABMultiValueCopyValueAtIndex với một định danh thay vì một chỉ mục.

Bạn phải gọi ABMultiValueGetIndexForIdentifier và sau đó sử dụng chỉ mục đó trên ABMultiValueCopyValueAtIndex.

Điểm mấu chốt là Identifier!=index.

0

Tôi chắc chắn rằng bạn đang thực sự xử lý loại bản ghi giá trị đa giá trị hợp lệ.

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

Thực ra, có thể an toàn hơn để đảm bảo rằng đó thực sự là một chuỗi.

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

Tôi không biết tại sao điều này không xảy ra. Có thể bạn đã nhập các mục liên hệ bị hỏng? Hoặc có thể đôi khi số điện thoại không phải là một loại giá trị đa?

2

Thay vì sử dụng

ABMultiValueCopyValueAtIndex(multiValue, identifier);

nào Zebs chỉ ra ở trên, sử dụng ...

ABMultiValueCopyValueAtIndex(multiValue, ABMultiValueGetIndexForIdentifier(multiValue, identifier)); 
Các vấn đề liên quan