2009-12-09 180 views
2

我目前能夠成功訪問並從peoplePickerNavigationController獲取數據,但是我想要做的是讓聯繫人的電子郵件地址被訪問,然後當聯繫人名字被按下。從iPhone地址簿中獲取電子郵件地址

場景:

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

回答

5

這是我做的。

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

    ... 

    CFRelease(prop); 
    [email release]; 
} 
+0

現在我把這個放在'peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:'method?因爲這是做同樣的事情我提供的代碼... – rson 2009-12-09 21:30:46

+0

抱歉,是的,需要在方法中,然後如果你打開PeoplePicker模態,你需要關閉它,因爲你有以上。 – 2009-12-10 00:31:47

相關問題