我想在PeoplePickerNavigationController上显示ABPersonVIewController。但它在iOS 8中不起作用。这是我使用过的代码。
ABPersonViewController *personVC = [[ABPersonViewController alloc] init];
personVC.addressBook = peoplePicker.addressBook;
ABRecordID displayedPerson = contactId;
personVC.displayedPerson = ABAddressBookGetPersonWithRecordID(peoplePicker.addressBook, displayedPerson);
[peoplePicker pushViewController: personVC animated:NO];
[self presentViewController: peoplePicker animated:NO completion:nil];
可能是什么原因以及如何解决这个问题。
答案 0 :(得分:0)
这将允许您打开人员选择器并从联系人中选择信息。我不知道你需要什么信息,但你明白了。
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
[self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person property:property identifier:identifier];
NSString *contactName = CFBridgingRelease(ABRecordCopyCompositeName(person));
self.nameField.text = [NSString stringWithFormat:@"%@", contactName ? contactName : @"No Name"];
ABMultiValueRef phoneRecord = ABRecordCopyValue(person, kABPersonPhoneProperty);
CFStringRef phoneNumber = ABMultiValueCopyValueAtIndex(phoneRecord, 0);
self.phoneField.text = (__bridge_transfer NSString *)phoneNumber;
CFRelease(phoneRecord);
ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty);
CFStringRef emailField = ABMultiValueCopyValueAtIndex(email, 0);
self.emailField.text = (__bridge_transfer NSString *)emailField;
CFRelease(email);
CFDataRef photo = ABPersonCopyImageData(person);
UIImage* image = [UIImage imageWithData:(__bridge NSData*)photo];
if(photo)
CFRelease(photo);
if(image)
self.myImageView.image = image;
[self dismissViewControllerAnimated:YES completion:nil];
return NO;
}
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
[self dismissViewControllerAnimated:YES completion:nil];
return NO; }