ios - How to use CNContactPickerViewController with objective c? -


hi i'm new ios development. want pick contact default contacts app. created application lets user pick contact iphone default contacts app. ios 9+ version, i'm using following snipped.

- (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"); } 

i added cncontactpickerdelegate delegate in uiviewcontroller. when execute above code, opens contacts app, when tap contact app becomes blank.

thanks in advance , can please share knowledge use cncontactpickerviewcontroller in objective-c.

the issue caused code:

contactpicker.displayedpropertykeys = (nsarray *)cncontactgivennamekey; 

the displayedpropertykeys expects nsarray contains nsstring values. in code, trying type cast nsstring nsarray , set value of property.

you need change code to:

contactpicker.displayedpropertykeys = @[cncontactgivennamekey]; 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -