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
Post a Comment