在iPad的AddressBook中,当我尝试添加电子邮件时,我可以选择设置自己的自定义标签并发送电子邮件,
问题: 我无法获取该特定标签及其价值,我可以从地址簿获取其他,iCloud,家庭,工作电子邮件ID。
这是与我所做的相关的代码:
//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;
}
}
}
答案 0 :(得分:0)
最后我得到了这个答案https://stackoverflow.com/a/5369704/1079929
并使用此代码获取输出: 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);
}