Kalの回答は実際には不正確です。つまり、「ABMultiValueCopyValueAtIndex」は識別子ではなくインデックスを使用するためです。
識別子の値は静的です(列挙のように)
- 「自宅のメールアドレス」は常に「0」です
- 「仕事用メール」は常に「1」です。
そのため、選択した人が「仕事用メール」である1通のメールしか保存していない場合はクラッシュします。識別子は「1」ですが、インデックス「0」が必要です。
幸い、以下を使用してインデックスを取得できます。
int index = ABMultiValueGetIndexForIdentifier(emails, identifier);
コード:
if (property == kABPersonEmailProperty) {
ABMultiValueRef emails = ABRecordCopyValue(person, property);
NSString *count = [NSString stringWithFormat:@"Count: %d Identifier: %d", ABMultiValueGetCount(emails), identifier];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:count delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
if(ABMultiValueGetCount(emails) > 0)
{
int index = ABMultiValueGetIndexForIdentifier(emails, identifier);
CFStringRef emailTypeSelected = ABMultiValueCopyLabelAtIndex(emails, index);
CFStringRef emailTypeSelectedLocalized = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(emails, index));
CFStringRef emailValueSelected = ABMultiValueCopyValueAtIndex(emails, index);
self.lblEmailType.text = (NSString *) emailTypeSelected;
self.lblEmailTypeLocalized.text = (NSString *) emailTypeSelectedLocalized;
self.lblEmailValue.text = (NSString *) emailValueSelected;
}
[ self dismissModalViewControllerAnimated:YES ];
return NO;
}
return YES;