Can we access the emailids from the contactlist from iPhone?

前端 未结 2 1868
星月不相逢
星月不相逢 2021-02-01 11:33

Can we access all the email IDs for each contact from the iPhone contactlist through code?

相关标签:
2条回答
  • 2021-02-01 11:56

    You will get the individual email ids by given code...

        ABAddressBookRef addressBook = ABAddressBookCreate();
        CFArrayRef people  = ABAddressBookCopyArrayOfAllPeople(addressBook);
        NSString *contactName = lblTitle.text;
        for(int i = 0;i<ABAddressBookGetPersonCount(addressBook);i++)
        {
            ABRecordRef person = CFArrayGetValueAtIndex(people, i);
            NSString *strEmail = [arContactData valueForKey:@"Email"];
            NSMutableArray *arEmailList = [[NSMutableArray alloc] init];
            ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
            for(CFIndex idx = 0; idx < ABMultiValueGetCount(emails); idx++)
            {
                CFStringRef emailRef = ABMultiValueCopyValueAtIndex(emails, idx);
                NSString *strLbl = (NSString*)ABAddressBookCopyLocalizedLabel (ABMultiValueCopyLabelAtIndex (emails, idx));
                NSDictionary *dicTemp = [[NSDictionary alloc]initWithObjectsAndKeys:strEmail,@"value", strLbl,@"label", nil];  
                [arEmailList addObject:dicTemp];        
            }
        }
    
    0 讨论(0)
  • 2021-02-01 12:10

    Sure, use the ABAdressBook class:

    ABAddressBookRef addressBook = ABAddressBookCreate(); NSArray *allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);

    Now you have all contacts in the allPeople array, then just get the email by key.

    0 讨论(0)
提交回复
热议问题