6

アプリがクラッシュします。これはAddressBookAPIから発生する問題であり、一部の連絡先でのみ発生します。

ログは次のとおりです。

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"];
4

3 に答える 3

12

同様の問題を経験している人へ:

私のエラーは、私が使用していたという事実から来ました:

ABMultiValueCopyValueAtIndexインデックスの代わりに識別子を使用します。

を呼び出してからABMultiValueGetIndexForIdentifier、でそのインデックスを使用する必要がありABMultiValueCopyValueAtIndexます。

一番下の行はIdentifier!=indexです。

于 2010-10-09T01:27:25.793 に答える
2

使用する代わりに

ABMultiValueCopyValueAtIndex(multiValue, identifier);

Zebsが上で指摘したものを使用してください...

ABMultiValueCopyValueAtIndex(multiValue, ABMultiValueGetIndexForIdentifier(multiValue, identifier));
于 2011-01-15T07:44:25.377 に答える
0

私はあなたが本当に有効な複数値のレコードタイプを扱っていることを確認します。

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

実際には、それが本当に文字列であることを確認する方がおそらく安全でしょう。

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

なぜそうならないのかわかりません。連絡先のエントリが破損している可能性がありますか?または、電話番号が複数値型ではない場合もありますか?

于 2010-10-01T05:12:50.940 に答える