由于我已将iPhone上的XCode(6.0,6A313)和我的iOS(8.0,12A365)更新为gm种子,因此ABPeoplePickerNavigationController代码不像以前那样工作.
iOS 7.1.2:如果有人想要导入联系人,则会打开地址簿,并且您会看到完整的联系人列表,选择一个联系人后,它会打开联系人的详细信息视图,而不是您可以通过单击电话添加联系人您要导入的号码.
iOS 8.0:它的一切都很相似,但如果你点击一个联系人的号码,它拨打电话号码而不是导入它.
码:
#pragma mark - AddressBook Delegate Methods
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{
return YES;
}
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
// Get the first and the last name. Actually, copy their values using the person object and the appropriate
// properties into two string variables equivalently.
// Watch out the ABRecordCopyValue method below. Also, notice that we cast to NSString *.
NSString *firstName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
// Compose …Run Code Online (Sandbox Code Playgroud) 我正在尝试自定义ABPeoplePickerNavigationController的导航栏,通过添加自定义UIBarButtonItem作为UINavigationController顶视图控制器的左右barbuttonitem .此功能在iOS7和以前的版本中运行良好,但在iOS 8中没有.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
navigationController.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNewContact:)];
navigationController.topViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel:)];
}
Run Code Online (Sandbox Code Playgroud)
上面的代码正在执行,但它没有任何效果.PeoplePickerNavigationController显示其默认导航栏,其默认项为"组"和"取消"按钮.
iOS 8有什么变化?我需要重新实施,我已经做了什么?
编辑:我在导航堆栈中记录了顶部的ViewController.它被称为CNContactPicker.
我想构建一个ContactsTableViewController类似GroupMe的东西.它显示了我的所有地址簿联系人,甚至是GroupMe用户.

似乎ABPeoplePickerNavigationController无法自定义.
那么,如果我使用ABAddressBook&访问地址簿联系人,ABPerson用自定义显示它们的最佳方式是UITableViewController什么?
我不想只是将所有地址簿联系人加载到一个,NSArray因为这可能会破坏内存(我知道在他们的手机上有数千个地址簿联系人的人.).我习惯使用Core Data和NSFetchedResultsController像这样的大型结果集.但是,要做到这一点,我必须ABPerson在Core Data中创建一个模型,这很容易,但保持与地址簿同步似乎具有挑战性和愚蠢.
将GroupMe联系人与地址簿联系人关联/链接的最佳方式是什么?
在尝试重新创建这个GroupMe风格的界面时,还有什么我应该知道/考虑的吗?
我有一个新项目,我想在触摸按钮时显示人员选择器.
所以我有一个带有标识符UIButton的泛型.我将此ViewController的类设置为.UIViewControllershowContactsABPeoplePickerNavigationController
现在在我的根ViewController中我有这个代码来初始化我的选择器:
#pragma mark - Segues
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"showContacts"]){
ABPeoplePickerNavigationController *ppnc = segue.destinationViewController;
ppnc.peoplePickerDelegate = self;
ppnc.addressBook = ABAddressBookCreate();
ppnc.displayedProperties = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonPhoneProperty]];
}
}
Run Code Online (Sandbox Code Playgroud)
虽然我已将测试联系人添加到我的模拟器地址簿中,但结果如下所示:
没有选择器http://i.minus.com/jbwUQyLr36ChH.png
使用以下代码,这与我在prepareForSegue:方法中的操作非常相似,我设法通过以下代码显示选择器IBAction:
- (IBAction)showPicker:(id)sender {
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty],
[NSNumber numberWithInt:kABPersonEmailProperty],
[NSNumber numberWithInt:kABPersonBirthdayProperty], nil];
picker.displayedProperties = displayedItems;
// Show the picker
[self presentModalViewController:picker animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
结果:
选择器http://i.minus.com/jeEVeIBmfIYdR.png
我不清楚为什么人物选择器没有显示.
我在UIPopoverController中有一个人物选择器,因为它有一个搜索字段,在点击时会触发键盘,然后我得到了这个丑陋的结果:

popover的箭头是UP,这是我的应用程序中最好的外观,我也尝试使用UP | DOWN但它不起作用(仍然总是UP),我知道我只能使用DOWN箭头,但那应该是最后一个解决方案,我想知道有没有任何方法可以解决这个问题?
谢谢!
更新:我在想,我可以先使用上箭头,然后在搜索领域成为第一个响应(不知道如何检测这一点),我将其更改为向下箭头(也不清楚如何做到这一点)?
更新2:视图也不是可以滚动的表或其他东西,因此我无法滚动视图以使弹出窗口看起来很好.
我正在使用ABAddressBookRef我的电话簿获取人员信息.它工作正常,但我想改变颜色UINavigationBar的ABPeoplePickerNavigationController.
这可能吗?如果可能的话,请告诉我怎么做.
更新2,我希望这有助于某人,有以下链接的解决方案:https://discussions.apple.com/thread/5498630? start = 0& tstart = 0,显然这是一个iOS错误,这个工作有效.我可以创建新的sharedPicker,但是我无法从中获取任何内容或者忽略它,我不确定如何格式化超出链接提供的内容 任何帮助都非常受欢迎.
所以我现在的问题是如何采用以下代码并实际为peoplePickerNavigationControllerDidCancel创建代码:和peoplePickerNavigationController:shouldContinueAfterSelectingPerson:谢谢.我已离开原始帖子的大部分,以防某人有类似的模糊问题.
// Convoluted workaround for the iPhone 4S crash
+ (ABPeoplePickerNavigationController *)sharedPeoplePicker {
static ABPeoplePickerNavigationController *_sharedPicker = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedPicker = [[ABPeoplePickerNavigationController alloc] init];
});
return _sharedPicker;
}
// then later on, use
[YourController sharedPeoplePicker].delegate = self;
// etc.
Run Code Online (Sandbox Code Playgroud)
我目前的代码:
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
[self displayPerson:person];
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
return NO;
}
- (void)peoplePickerNavigationControllerDidCancel:
(ABPeoplePickerNavigationController *)peoplePicker
{
//[self dismissViewControllerAnimated:YES completion:nil]; …Run Code Online (Sandbox Code Playgroud) 使用ABPeoplePickerNavigationController时需要片刻(~0.5秒)加载并显示比其他弹出窗口的正常反应时间慢的控件.
我带来了解决方案,将控制器设置为变量,并通过以下方式访问此预加载对象:
[self presentViewController:self.peoplePicker animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
出于好奇,有没有另外一种方法可以在没有预加载的情况下点亮拣货员?
我需要允许用户从iPhone地址簿中选择多个条目,然后再继续下一个操作.
目前,如果我使用ABPeopleNavigationController,它只允许我一次选择一个条目.有没有办法允许多个选择,即在点击"完成"按钮之前在我想要选择的所有名称旁边添加一个复选标记
在ios8中,我想访问联系人属性,如果他有多个号码电话,但我不知道如何在iOS8中这样做.
这是我在iOS7中的代码:
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{
//If person has just one phone number
ABMultiValueRef phonesRef = ABRecordCopyValue(person, kABPersonPhoneProperty);
if(ABMultiValueGetCount(phonesRef) == 1){
CPIContact* contact = [self getCPIContactFromPerson:person andPhoneIndex:0];
[self addContact:contact];
// Dismiss the address book view controller.
[_addressBookController dismissViewControllerAnimated:YES completion:nil];
return NO;
}else if(ABMultiValueGetCount(phonesRef) == 0){
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Common_information",nil) message:NSLocalizedString(@"EditCallSMS_noNumber", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"Common_ok",nil) otherButtonTitles:nil] show];
return NO;
}
else{
return YES;
}
}
Run Code Online (Sandbox Code Playgroud)
我知道我必须使用iOS8中的didSelectPerson方法,但我不知道如何告诉应用程序在选择像iOS7这样的人之后可以继续.
我在Apple文档中读到了关于predicateForSelectionOfPerson但我不明白如何使用它.
预先感谢您的帮助.