1

ピープルピッカーで実際にデータを取得するのにAppleのドキュメントがあまり役に立たないと思っています。また、インターネット上に他の情報はあまりないようです:(この関数でメールを取得する必要があると思います:

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

}

選択した人のメールを受け取るためにそこに何を入れることができますか?

4

2 に答える 2

4

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;
于 2012-03-30T03:59:05.547 に答える
0

使用する

ABMultiValueRef emails = ABRecordCopyValue(record, kABPersonEmailProperty);

その後、ABMultiValueRefsAPIメソッド呼び出しを使用して電子メールアドレスを取得できます。

編集-これはあなたに電子メールを与えるはずです

CFStringRef emailId = ABMultiValueCopyValueAtIndex(emails, identifier);
于 2011-07-18T17:43:34.533 に答える