I'm fetching contacts from address book but popup not show to ask permission to access contacts. it automatically denied but when i try same code in a demo then it run properly but it ddi not run in my app. I have read many articles but i did not get any solution. Is i'm missing something in plist or settings.
CNContactStore * contactStore = [[CNContactStore alloc]init];
if ([CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts] == CNAuthorizationStatusNotDetermined) {
[contactStore requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * __nullable error) {
if (granted==YES)
{
}
else
{
NSLog(@"Error");
}
}];
}
or second methods
CFErrorRef error = nil;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error)
{
if (error)
{
NSLog(@"error %@", error);
}
else if (granted)
{
}
CFRelease(addressBook);
});
}