How to get Custom label and value of the Email in ABAddressBook

我与影子孤独终老i 提交于 2019-12-25 06:18:05

问题


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,

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;

                    }
            }
}

回答1:


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

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);
        }


来源:https://stackoverflow.com/questions/21978099/how-to-get-custom-label-and-value-of-the-email-in-abaddressbook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!