kABPersonEmailProperty 返回奇怪的东西

发布于 2024-11-19 13:49:02 字数 487 浏览 5 评论 0原文

我试图获取 ABRecordRef 的电子邮件地址,如下所示:

ABRecordRef ref = CFArrayGetValueAtIndex( allPeople, i );
NSString *email = [(NSString*) ABRecordCopyValue( ref, kABPersonEmailProperty ) autorelease];
NSLog(@"%@", email);

它返回:

_$!<Home>!$_ (0x6840af0) - [email protected] (0x6840cc0)

电子邮件周围的这些东西是什么?我怎样才能摆脱它?谢谢。

I am tring to get email address of ABRecordRef like this:

ABRecordRef ref = CFArrayGetValueAtIndex( allPeople, i );
NSString *email = [(NSString*) ABRecordCopyValue( ref, kABPersonEmailProperty ) autorelease];
NSLog(@"%@", email);

It returning this:

_$!<Home>!$_ (0x6840af0) - [email protected] (0x6840cc0)

What's this stuff around the email? and how can I get rid of it?Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

墨洒年华 2024-11-26 13:49:02

kABPersonEmailProperty 的类型为 kABMultiStringPropertyType。没有单一的电子邮件地址属性,一个人可能有一个用于工作的电子邮件地址,一个用于家庭的电子邮件地址,等等。
您可以使用 ABMultiValueCopyArrayOfAllValues 获取所有电子邮件地址的数组:

ABMultiValueRef emailMultiValue = ABRecordCopyValue(ref, kABPersonEmailProperty);
NSArray *emailAddresses = [(NSArray *)ABMultiValueCopyArrayOfAllValues(emailMultiValue) autorelease];
CFRelease(emailMultiValue);

要获取电子邮件地址的标签,请使用 ABMultiValueCopyLabelAtIndex。 “_$!!$”是一个特殊常量,定义为kABHomeLabel,还有kABWorkLabel

kABPersonEmailProperty is of type kABMultiStringPropertyType. There is no single email address property, a person might have an email address for work, one for home, etc.
You can get an array of all email addresses by using ABMultiValueCopyArrayOfAllValues:

ABMultiValueRef emailMultiValue = ABRecordCopyValue(ref, kABPersonEmailProperty);
NSArray *emailAddresses = [(NSArray *)ABMultiValueCopyArrayOfAllValues(emailMultiValue) autorelease];
CFRelease(emailMultiValue);

To get the labels of the email addresses, use ABMultiValueCopyLabelAtIndex. "_$!<Home>!$" is a special constant that's defined as kABHomeLabel, there's also kABWorkLabel.

心如狂蝶 2024-11-26 13:49:02

基本上是 @omz 答案的更多细节。这是我用来提取家庭电子邮件和人员姓名的代码:

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
    ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
    for (CFIndex i = 0; i < ABMultiValueGetCount(emails); i++) {
        NSString *label = (__bridge NSString *) ABMultiValueCopyLabelAtIndex(emails, i);
        if ([label isEqualToString:(NSString *)kABHomeLabel]) {
            NSString *email = (__bridge NSString *) ABMultiValueCopyValueAtIndex(emails, i);
            _emailTextField.text = email;
        }
    }
    CFRelease(emails);


    NSString *first = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
    NSString *last = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);

    if (first && first.length > 0 && last && last.length > 0) {
        _nicknameTextField.text = [NSString stringWithFormat:@"%@ %@", first, last];
    } else if (first && first.length > 0) {
        _nicknameTextField.text = first;
    } else {
        _nicknameTextField.text = last;
    }

    [self dismissModalViewControllerAnimated:YES];

    return NO;
}

Basically more details for @omz answer. Here is the code I used that extracts home email and the name of the person:

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
    ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
    for (CFIndex i = 0; i < ABMultiValueGetCount(emails); i++) {
        NSString *label = (__bridge NSString *) ABMultiValueCopyLabelAtIndex(emails, i);
        if ([label isEqualToString:(NSString *)kABHomeLabel]) {
            NSString *email = (__bridge NSString *) ABMultiValueCopyValueAtIndex(emails, i);
            _emailTextField.text = email;
        }
    }
    CFRelease(emails);


    NSString *first = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
    NSString *last = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);

    if (first && first.length > 0 && last && last.length > 0) {
        _nicknameTextField.text = [NSString stringWithFormat:@"%@ %@", first, last];
    } else if (first && first.length > 0) {
        _nicknameTextField.text = first;
    } else {
        _nicknameTextField.text = last;
    }

    [self dismissModalViewControllerAnimated:YES];

    return NO;
}
宣告ˉ结束 2024-11-26 13:49:02

试试这个......

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
// Display only a person's phone, email, and birthdate
NSArray *displayedItems = [NSArray arrayWithObjects:
[NSNumber numberWithInt:kABPersonPhoneProperty],
[NSNumber numberWithInt:kABPersonEmailProperty],
[NSNumber numberWithInt:kABPersonBirthdayProperty], nil];
picker.displayedProperties = displayedItems;

Try out this......

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
// Display only a person's phone, email, and birthdate
NSArray *displayedItems = [NSArray arrayWithObjects:
[NSNumber numberWithInt:kABPersonPhoneProperty],
[NSNumber numberWithInt:kABPersonEmailProperty],
[NSNumber numberWithInt:kABPersonBirthdayProperty], nil];
picker.displayedProperties = displayedItems;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文