4

I use CNContactPickerViewController and I want to hide actions buttons (call, message, facetime) from contact's detail.

I know about allowActions property in CNContactViewController, but I don't know, how I can get access to this property, if I use CNContacPickerViewController.

How I can hide actions buttons from contact's detail when using CNContactPickerViewController?

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
Artem
  • 83
  • 1
  • 6

1 Answers1

0

You can't use allowActions property with CNContactPickerViewController. I am using this approach and its not showing details of any contact, it only shows list like this enter image description here

After that you can select any contact and delegate method will give you contact details of that contact.

-(void) openDeviceContactList {
    CNContactPickerViewController *contactPicker = [CNContactPickerViewController new];
    contactPicker.delegate = self;
    [self presentViewController:contactPicker animated:YES completion:nil];
}

- (void) contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact {
    [self getPhoneNumberFrom:contact];
}

-(void)getPhoneNumberFrom:(CNContact *)contactObject {

    NSString * phone = @"";
    NSString * userPHONE_NO = @"";
    for(CNLabeledValue * phonelabel in contactObject.phoneNumbers) {
        CNPhoneNumber * phoneNo = phonelabel.value;
        phone = [phoneNo stringValue];
        if (phone) {
            userPHONE_NO = phone;
        }
        break;
    }
    NSLog(@"PHONE NO :: %@",userPHONE_NO);
}

Call [self openDeviceContactList]; on button tap from which you want to open contact list. This will present CNContactPickerViewController. For this cause you have to implement CNContactPickerDelegate and also you have to add ContactsUI.framework and Contacts.frameworkfrom Build Settings.

This is working code.

IMP NOTE: This will work iOS 9.0 onwards only. If you are supporting 8.0 onwards then add OS check and use AddressBook.framework & AddressBookUI.framework

Pushkraj Lanjekar
  • 2,254
  • 1
  • 21
  • 34
  • CNContactPickerViewController doesn't have an allowActions property. – Artem Dec 14 '16 at 16:47
  • @ArtemUpdated answer, please check. And its working solution from y current project. – Pushkraj Lanjekar Dec 14 '16 at 18:36
  • No, I need to show contact details and I want to hide actions button. http://www.howtogeek.com/wp-content/uploads/2016/09/pcm_top.png it is example which buttons I want to hide. Maybe I need to show CNContactViewController in didSelectContact delegate? – Artem Dec 15 '16 at 08:45