代码之家  ›  专栏  ›  技术社区  ›  rson

从iPhone通讯簿获取电子邮件地址

  •  2
  • rson  · 技术社区  · 16 年前

    我目前能够成功地从 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;
    }
    
    1 回复  |  直到 16 年前
        1
  •  5
  •   John Stallings    16 年前

    这是我的工作。

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