IOS 13 CNContacts No Longer Working To Retrieve All Contacts
Asked Answered
C

3

17

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?

Caroleecarolin answered 10/8, 2019 at 12:22 Comment(4)
Looks to be related to this new entitlement: developer.apple.com/documentation/bundleresources/entitlements/…Austronesian
@Petesh that looks like exactly what it is, I really wish they made the changes more obvious. Also If I can't get an entitlement accepted for my app all, I'll need to employ a work around, at huge inconvenience to my customers. If you post the above as an answer I will accept it as a solution. Thanks for the info.Caroleecarolin
@Caroleecarolin have you been able to get approved for this entitlement? We requested approval weeks ago and have heard nothing from Apple.Rappee
I applied for the entitlement, but was taking too long, so I redesigned my app so it doesn't need the entitlement, and managed to keep all the features. The update was accepted and I'm all sorted, not sure it will be as easy for others but I wish you luck.Caroleecarolin
A
26

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.

Austronesian answered 15/8, 2019 at 21:43 Comment(7)
have you been able to get approval for this entitlement? We requested permission using the link above weeks ago and we cannot get an answer from Apple.Rappee
No, I've heard nothing from apple, and it's not visible in the provisioning UI on the website, or in XCode. It appears to be a 'dropped the ball' issue - I would suggest filing an issue about it.Austronesian
I filed a developer issue and the response was apply for permission to use the profile, and I expect if you get approved it will appear in the provisioning profile for the app, but otherwise will be unusable. In the interim I just nixed getting the notes field as it was not needed for my use caseAustronesian
Thanks @Petesh, we finally got in contact with the internal review team and they said they expect our review to be complete this week. Their reason for the delay was the number of requests they received.Rappee
Do enterprise apps need this request approved by Apple as well? I ask as the link says "Before you can submit an app with this entitlement to the App Store, you must first get permission to use the entitlement.".Homebred
@VaibhavMisra I don't know. I have no experience with special entitlements for enterprise apps.Austronesian
Someone received answer for the request?Hacksaw
L
9

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.

Lafayette answered 15/8, 2019 at 10:47 Comment(2)
Turns out its not a bug, see comment by @Petesh above and this link here .. developer.apple.com/documentation/bundleresources/entitlements/…Caroleecarolin
Wouldn't the bug be: give me an error message that says which key was the offending key?Runnel
P
3

The latest com.apple.developer.contacts.notes entitlement for iOS 13 is not updated in Xcode as well as in-app id configuration in Apple developer portal. Currently, we are blocked because of the same. Can someone please let us know how to proceed with this. If we add com.apple.developer.contacts.notes manually to an entitlement, it throws an error which says:

Provisioning profile "iOS Development Profile" doesn't include the com.apple.developer.contacts.notes entitlement.

Thanks,
Sanath

Protagoras answered 26/9, 2019 at 10:33 Comment(2)
I have the same problem. Did you find any solution ?Unscientific
you need to request the permission, it's the only way for now. developer.apple.com/contact/request/contact-note-fieldMalkin

© 2022 - 2024 — McMap. All rights reserved.