我现在能够从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;
}
有帮助吗?

解决方案

下面是我做什么。

if(property == kABPersonEmailProperty) {
  CFTypeRef prop = ABRecordCopyValue(person, property);
  CFIndex index = ABMultiValueGetIndexForIdentifier(prop,  identifierForValue);
  NSString *email = (NSString *)ABMultiValueCopyValueAtIndex(prop, index);

  ...

  CFRelease(prop);
  [email release];
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top