-1

I'm trying to open Address book using new Contacts.framework. This framework is introduced in iOS 9.0, I've tried some ways to open the view controller but ends up crashing. Has anyone faced similar issue?

NSError *error;

CNContactStore *store = [[CNContactStore alloc] init];
NSArray *cArray = [store unifiedContactsMatchingPredicate:[CNContact predicateForContactsMatchingName:@"Kate"] keysToFetch:@[CNContactEmailAddressesKey,CNContactPhoneNumbersKey] error:&error];

CNContactViewController *cVC = [CNContactViewController viewControllerForContact:[cArray objectAtIndex:0]];
[self presentViewController:cVC animated:YES completion:^{

}];
Bhanu Birani
  • 1,286
  • 1
  • 13
  • 22

2 Answers2

3

Since Contacts.framework is only available in iOS 9.0 onwards. Here is the code which checks for the availability and because launching contact picker view controller.

Code to invoke contact picker view controller

if ([CNContactPickerViewController class]) {
     CNContactPickerViewController *cVC = [[CNContactPickerViewController alloc] init];
     [self.view.window.rootViewController presentViewController:cVC animated:YES completion:nil];
}
Bhanu Birani
  • 1,286
  • 1
  • 13
  • 22
1

Swift 4.x

let contactPicker = CNContactPickerViewController()
contactPicker.delegate = self
self.present(contactPicker, animated: true, completion: nil)
Jaydeep Vora
  • 6,085
  • 1
  • 22
  • 40