【发布时间】:2017-09-10 18:43:44
【问题描述】:
我有一个使用 ABPeoplePickerNavigationController 来选择联系人电子邮件地址的 Objective C 项目。
代码是这样的:
-(IBAction)_email_contactsbuttonpushed_orig:(UIButton*)contactsbutton {
[AnalyticsWrapper logEvent:@"share_via_contacts_clicked"];
// ABPeoplePickerNavigationController
_contactPicker = [[ABPeoplePickerNavigationController alloc] init];
_contactPicker.peoplePickerDelegate = self;
_contactPicker.delegate = self;
// Define properties to show when viewing a specific person
_contactPicker.displayedProperties = [NSArray arrayWithObjects:@(kABPersonEmailProperty), nil];
// Style the nav bar
[[QPDrawing shared] paintNavBarInController:_contactPicker];
// showing the picker
if (isIpad) {
self.peoplePopoverController = [[UIPopoverController alloc] initWithContentViewController:_contactPicker];
_peoplePopoverController.delegate = self;
CGRect b = self.homeViewController.view.bounds;
CGRect b2 = (CGRect){
b.size.width/2-5,0,
10,self.homeViewController.headerview.bounds.size.height
};
b2 = _emailContactsButton.frame;
b2.origin.y += self.view.frame.origin.y; // push box down to account for header
[_peoplePopoverController presentPopoverFromRect:b2
inView:self.homeViewController.view
permittedArrowDirections: UIPopoverArrowDirectionAny
animated:YES];
}
else {
[self.homeViewController presentViewController:_contactPicker animated:YES completion:nil];
}
}
弹出窗口看起来不错,我可以选择一个联系人。 当我选择一个联系人时,它会打开联系人详细信息。 但是,当我点击一个电子邮件地址时,它会切换到电子邮件应用程序并正在撰写电子邮件——就像我打开了我的联系人应用程序等一样。
peoplePickerNavigationController:didSelectPerson 的回调永远不会被调用。
这最初不是我的代码,但有人告诉我它可以使用。其他开发人员虽然没有在他的项目中工作,所以我不知道是否进行了破坏它的更改。我知道 PeoplePickerNavigationController 有点过时了。
任何帮助将不胜感激。谢谢!
编辑——关于委托方法的附加信息:
shouldContinueAfterSelectingPerson:
// Called after a person has been selected by the user.
// Return YES if you want the person to be displayed.
// Return NO to do nothing (the delegate is responsible for dismissing the peoplePicker).
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
_addressbookFirstName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
_addressbookLastName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
// Continue on to the person's details
return YES;
}
shouldContinueAfterSelectingPerson:property:identifier:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
if ( property != kABPersonEmailProperty ) {
return NO;
}
【问题讨论】:
-
除非您尝试支持 iOS 8,否则您应该使用较新的 ContactsUI 框架中的类,而不是旧的 AddressBookUI 框架。
-
直接在 iPad 上使用
UIPopoverController也已经过时了。 -
如果您真的需要有关此代码的帮助,您需要使用相关的委托方法更新您的问题。
-
我按照您的建议添加了委托方法。我只是在所有设备上重新编译并运行 UIPopoverController ,但那里没有任何改进。无论哪种方式,选择器都会出现,但不会发生实际的选择。
标签: ios objective-c