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?
In iOS 13, apple have added a new entitlement that is needed if you wish to access the notes for contacts.
The entitlement is com.apple.developer.contacts.notes
. You can request permission to use this entitlement for an app being put in the App Store.
The reason it was added is primarily for privacy reasons — the notes field can contain any information you might have on the contact; and a lot of times this information is significantly more sensitive than just the contact information.
As of 2019-08-15, this entitlement sits in the beta category, which means it may be subject to change before the release of iOS 13, and the name of the entitlement will probably stabilize in it’s presentation to the developer in Xcode.
For me this seemed to be caused by the presence of CNContactNoteKey in the "keys to fetch". Removing it restores functionality.
I see you have CNContactNoteKey present, too.
I have flagged this to Apple as a bug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With