嗨,我是 iOS 开发的新手。我想从默认联系人应用程序中选择一个联系人。为此,我创建了一个应用程序,允许用户从 iPhone 默认联系人应用程序中选择联系人。对于 iOS 9+ 版本,我正在使用以下截图。
- (IBAction)btnAction:(id)sender {
CNContactPickerViewController *contactPicker = [[CNContactPickerViewController alloc] init];
contactPicker.delegate = self;
contactPicker.displayedPropertyKeys = (NSArray *)CNContactGivenNameKey;
[self presentViewController:picker animated:YES completion:nil];
}
-(void) contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact{
NSLog(@"Contact : %@",contact);
}
-(void)contactPickerDidCancel:(CNContactPickerViewController *)picker {
NSLog(@"Cancelled");
}
我还在我的 uiviewcontroller 中添加了 CNContactPickerDelegate 委托。当我执行上述代码时,它会打开联系人应用程序,但是当点击联系人时,应用程序会变为空白。
在此先感谢,任何人都可以分享您在 Objective-C 中使用 CNContactPickerViewController 的知识。