开发者

Can we access the emailids from the contactlist from iPhone?

开发者 https://www.devze.com 2023-03-25 11:35 出处:网络
Can we access all the email开发者_运维技巧 IDs for each contact from the iPhone contactlist through code?You will get the individual email ids by given code...

Can we access all the email开发者_运维技巧 IDs for each contact from the iPhone contactlist through code?


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


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

精彩评论

暂无评论...
验证码 换一张
取 消