1

我正在将地址簿中的所有联系人添加到我的应用程序中,我只需要从所选联系人获取电子邮件地址,这是我的代码

shouldContinueAfterSelectingPerson

- (BOOL)peoplePickerNavigationController:

(ABPeoplePickerNavigationController *)peoplePicker

      shouldContinueAfterSelectingPerson:(ABRecordRef)person {


    // Select phone number


    ABMultiValueRef emailProperty = ABRecordCopyValue(person, kABPersonEmailProperty);


    NSString *email = (__bridge NSString *)(emailProperty);

    [self dismissModalViewControllerAnimated:YES];

    self.view.frame = CGRectMake(0, 44, 320, 370);


    return NO;

}

请帮助我摆脱这些人,在此先感谢

我在下面给出的日志中打印它

电子邮件字符串是 ABMultiValueRef 0x1eb2ddb0,值为 0

4

2 回答 2

3
CFStringRef value, label;
ABMutableMultiValueRef multi = ABRecordCopyValue(person, kABPersonEmailProperty);
CFIndex count = ABMultiValueGetCount(multi);
if (count == 1)
{
    value = ABMultiValueCopyValueAtIndex(multi, 0);
    emailid = (NSString*) value;
    NSLog(@"self.emailID   %@",emailid);
    CFRelease(value);
}
else
{
    for (CFIndex i = 0; i < count; i++)
    {
        label = ABMultiValueCopyLabelAtIndex(multi, i);
        value = ABMultiValueCopyValueAtIndex(multi, i);

        // check for Work e-mail label
        if (CFStringCompare(label, kABWorkLabel, 0) == 0)
        {
            emailid = (NSString*) value;
            NSLog(@"self.emailID   %@",emailid);
        }
        else if(CFStringCompare(label, kABHomeLabel, 0) == 0)
        {
            emailid = (NSString*) value;
            NSLog(@"self.emailID   %@",emailid);
        }

        CFRelease(label);
        CFRelease(value);
    }
}
CFRelease(multi);
于 2012-10-01T07:11:37.000 回答
1

您可以添加以下代码来访问电子邮件表单联系人..

-(IBAction)Contact 
{
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;
        [self presentModalViewController:picker animated:YES];
    [picker release];}
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
    [self dismissModalViewControllerAnimated:YES];
 }

- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
    ABMultiValueRef emailMultiValue = ABRecordCopyValue(person, kABPersonEmailProperty);
    NSArray *email = [(NSArray *)ABMultiValueCopyArrayOfAllValues(emailMultiValue) autorelease];
    CFRelease(emailMultiValue);
   [self dismissModalViewControllerAnimated:YES];}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
    return NO;
}
于 2012-10-01T11:54:10.307 回答