如何在ABAddressBook中获取电子邮件的自定义标签和值 [英] How to get Custom label and value of the Email in ABAddressBook

查看:144
本文介绍了如何在ABAddressBook中获取电子邮件的自定义标签和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPad的AddressBook中,当我尝试添加电子邮件时,我可以选择设置自己的自定义标签并提供电子邮件,

In AddressBook of iPad,when i am trying to add a email, I have an option to set my own Custom Label and give the email,

问题:
我无法获取该特定标签及其值,我可以从地址簿中获取其他iCloud,家庭,工作电子邮件ID。

Problem: I am not able to fetch that particular label and its value, I am able to get other,iCloud,home,work email IDs from Addressbook.

这是与我所做的事情相关的代码:

This is the Code related to what i have done:

    //Email
            ABMultiValueRef emailID = ABRecordCopyValue(recordRef, kABPersonEmailProperty);
            CFIndex emailCount = ABMultiValueGetCount(emailID);
    //        PSLog(@"counter %ld",emailCount);
            NSString *emailLabel;
            NSMutableArray *emailLabelsMutArr = [NSMutableArray new];

            if (emailCount == 0) {
                [nameEmailMutDict setValue:@"No Mail ID" forKey:kEmailKey];
            }
            else
            {
                for(CFIndex emailCounter = 0; emailCounter < emailCount; emailCounter++)
                {
                    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                    [dict setValue:contactFirstName forKey:kEmailFirstNameKey];
                    [dict setValue:contactLastName forKey:kEmailLastNameKey];
                    emailLabel = (__bridge NSString*)ABMultiValueCopyLabelAtIndex(emailID, emailCounter);
                    [emailLabelsMutArr addObject:emailLabel];
                    NSString *strEmail = (__bridge NSString *)(ABMultiValueCopyLabelAtIndex(emailID, emailCounter));

                    if ([emailLabel isEqualToString:@"_$!<Home>!$_"]) {
                        strEmail = (__bridge NSString*)ABMultiValueCopyValueAtIndex(emailID, emailCounter);
                        [dict setValue:strEmail forKey:kEmailKey];
                        contactsObject.contactEmailModal = strEmail;
                        [self.recordsMutableArray addObject:dict];
                        continue;

                    }
            }
}


推荐答案

最后,我通过遵循此答案得到 https://stackoverflow.com/a/5369704/1079929

At last i have got by following this answer https://stackoverflow.com/a/5369704/1079929

并使用以下代码获取我的输出:
ABMultiValueRef emails = ABRecordCopyValue(recordRef,kABPersonEmailProperty);

and got my output using this code : ABMultiValueRef emails = ABRecordCopyValue(recordRef, kABPersonEmailProperty);

for(CFIndex j = 0; j < ABMultiValueGetCount(emails); j++)
        {
            NSMutableDictionary *dict = [NSMutableDictionary dictionary];
            [dict setValue:contactFirstName forKey:kEmailFirstNameKey];
            [dict setValue:contactLastName forKey:kEmailLastNameKey];

            CFStringRef emailIDRef = ABMultiValueCopyValueAtIndex(emails, j);
            CFStringRef locLabel = ABMultiValueCopyLabelAtIndex(emails, j);
            NSString *emailLabel =(NSString*) ABAddressBookCopyLocalizedLabel(locLabel);
            //CFRelease(phones);
            NSString *emailID = (NSString *)emailIDRef;
            [dict setValue:emailID forKey:kEmailKey];
            contactsObject.contactEmailModal = emailID;
            [self.recordsMutableArray addObject:dict];
            NSLog(@"emailID  - %@ emailLabel %@", emailID, emailLabel);
        }

这篇关于如何在ABAddressBook中获取电子邮件的自定义标签和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆