I have an app that has worked perfectly well with the CNContacts framework all the way up to IOS 12. I'm currently testing it with IOS 13 beta and its completely broken. I've checked the contacts permissions and deleted the app and re-allowed the permissions. This is the code I'm using to retrieve all contacts:
NSError* error;
CNContactStore *store = [[CNContactStore alloc]init];
[store containersMatchingPredicate:[CNContainer predicateForContainersWithIdentifiers: @[store.defaultContainerIdentifier]] error:&error];
NSArray *keysToFetch =@[CNContactGivenNameKey, CNContactEmailAddressesKey, CNContactNoteKey];
CNContactFetchRequest *request = [[CNContactFetchRequest alloc]initWithKeysToFetch:keysToFetch];
BOOL success = [store enumerateContactsWithFetchRequest:request error:&error usingBlock:^(CNContact * __nonnull contact, BOOL * __nonnull stop){
NSLog(@"Contact Found: %@", contact.givenName);
}];
The contact store builds fine, and the error is nil. However when I then try to get the contacts via the fetch request I get success=NO and I receive the following error:
Error Domain=CNErrorDomain Code=102 "(null)" UserInfo={CNKeyPaths=(
note
), CNInvalidRecords=(
"<CNContactFetchRequest: 0x60000189aa00: predicate=(null), keysToFetch=(\n givenName,\n emailAddresses,\n note\n), unifyResults=1, sortOrder=0>"
I've tried various tweaks but I cannot get this to work at all. I also can't find any documentation to say this has behaviour has been changed.
Has anyone else also tried this or found a work around?