CNUI 错误选择谓词已设置但委托未实现 contactPicker:didSelectContact:

CNUI ERROR Selection predicates are set but the delegate does not implement contactPicker:didSelectContact:

我尝试使用新的 iOS 9.0 CNContactPickerViewController 来 select objective-C 中的联系人。我设置委托并实现 CNContactPickerDelegate 方法。

@import ContactsUI;
@import Contacts;
//-----------------------------------------------------------------------
- (void) presentContacts
{
    CNContactPickerViewController *contactPicker = [[CNContactPickerViewController alloc] init];
    contactPicker.delegate = self;
    contactPicker.predicateForEnablingContact = [NSPredicate predicateWithFormat:@"familyName LIKE[cd] 'smith'"];
    contactPicker.predicateForSelectionOfContact = [NSPredicate predicateWithFormat:@"TRUEPREDICATE"];
    [_myViewController presentViewController:contactPicker animated:YES completion:nil];
}
//-----------------------------------------------------------------------
- (void) contactPickerDidCancel: (CNContactPickerViewController *) picker
{
    NSLog(@"didCancel");
}
//-----------------------------------------------------------------------
- (void) contactPicker: (CNContactPickerViewController *) picker
      didSelectContact: (CNContact *)                     contact
{
    NSLog(@"didSelectContact"):
}
//-----------------------------------------------------------------------
- (void)      contactPicker: (CNContactPickerViewController *) picker
   didSelectContactProperty: (CNContactProperty *)             contactProperty
{
    NSLog(@"didSelectProperty");
}
//-----------------------------------------------------------------------

联系人选择器显示 'smith' selectable 但我收到以下消息:

[CNUI 错误] 已设置选择谓词,但委托未实现 contactPicker:didSelectContact: 和 contactPicker:didSelectContact属性:。这些谓词将被忽略。

而且我从来没有从委托方法中得到任何日志。它的行为与行

完全一样
    contactPicker.delegate = self;

被忽略。即使我单击选择器中的 "cancel" 按钮,我也没有收到 "didCancel" 消息,但我收到另一条消息:

插件com.apple.MobileAddressBook.ContactsViewService无效

我在 https://forums.developer.apple.com/thread/12275 中发现有人在 swift 中有类似的问题,他解决了它告诉我们:"So I found that the ContactsPicker I was calling was in the wrong module" 但我没有了解我们如何获得错误的模块以及如何调用 "right" 模块。

我在模拟器和真实设备上遇到了同样的问题 (iPad)。

感谢 Joel 在我的相关问题 中,我发现我只是忘记将 CNContactPickerViewController 存储在 属性 中用户做出选择。

所以我的代码变成了:

- (void) presentContacts
{
    _contactPicker = [[CNContactPickerViewController alloc] init];
    contactPicker.delegate = self;
    ...
}