IOS 13 CNContacts No Longer Working To Retrieve All Contacts

不羁的心 提交于 2020-01-01 04:16:08

问题


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?


回答1:


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.




回答2:


For me this seems to relate to 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.




回答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



来源:https://stackoverflow.com/questions/57442114/ios-13-cncontacts-no-longer-working-to-retrieve-all-contacts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!