0

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;

                    }
            }
}
iOSDev
  • 412
  • 10
  • 30

1 Answers1

0

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);
        }
Community
  • 1
  • 1
iOSDev
  • 412
  • 10
  • 30