我们可以从iPhone的联系人列表中访问电子邮件ID吗?

时间:2011-08-03 16:41:39

标签: iphone ios email contacts

我们可以通过代码从iPhone联系人列表中访问每个联系人的所有电子邮件ID吗?

2 个答案:

答案 0 :(得分:2)

您将通过给定代码获得各个电子邮件ID ...

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

答案 1 :(得分:0)

当然,请使用ABAdressBook类:

  

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

现在你拥有allPeople数组中的所有联系人,然后只需按键获取电子邮件。