【问题标题】:Get Email address from iPhone Address Book从 iPhone 地址簿获取电子邮件地址
【发布时间】:2009-12-09 16:38:33
【问题描述】:

我目前能够成功访问并从peoplePickerNavigationController 获取数据,但我想做的是访问联系人的电子邮件地址,然后在按下联系人姓名时关闭模式窗口。

场景:

"Button is clicked to add a contact
AddressBook Modal Window slides into view
Name of Contact is pressed
If available, the contact's email address is stored in an array
Dismiss modal window"

我当前的代码包括:

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
    ABMultiValueRef container = ABRecordCopyValue(person, property);
    CFStringRef contactData = ABMultiValueCopyValueAtIndex(container, identifier);
    CFRelease(container);
    NSString *contactString = [NSString stringWithString:(NSString *)contactData];
    CFRelease(contactData);

    NSLog(@"Value is: %@", contactString);

    [self dismissModalViewControllerAnimated:YES];  
    return NO;
}

【问题讨论】:

    标签: iphone addressbook


    【解决方案1】:

    这就是我的工作。

    if(property == kABPersonEmailProperty) {
      CFTypeRef prop = ABRecordCopyValue(person, property);
      CFIndex index = ABMultiValueGetIndexForIdentifier(prop,  identifierForValue);
      NSString *email = (NSString *)ABMultiValueCopyValueAtIndex(prop, index);
    
      ...
    
      CFRelease(prop);
      [email release];
    }
    

    【讨论】:

    • 现在我要把它放在peoplePickerNavigationController: shouldContinueAfterSelectingPerson: property: identifier: 方法中吗?因为这和我提供的代码做的一样...
    • 对不起,是的,需要在方法中,然后如果您以模态方式打开 PeoplePicker,您需要像上面一样将其关闭。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-01
    • 2011-03-27
    • 2013-04-18
    • 2015-11-23
    • 2013-09-29
    • 2014-06-01
    相关资源
    最近更新 更多