IOS 13 CNContacts不再工作以检索所有联系人 [英] IOS 13 CNContacts No Longer Working To Retrieve All Contacts

查看:312
本文介绍了IOS 13 CNContacts不再工作以检索所有联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与CNContacts框架在IOS 12之前一直运行良好的应用程序.我目前正在使用IOS 13 beta对其进行测试,并且该应用程序已经完全损坏.我已经检查了联系人权限,并删除了该应用程序并重新允许了该权限.这是我用来检索所有联系人的代码:

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);

}];

联系人存储建立良好,错误为nil.但是,当我随后尝试通过提取请求获取联系人时,我得到 success = NO ,并且收到以下错误消息:

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?

推荐答案

在iOS 13中,苹果添加了新的权利,如果您希望访问联系人的注释,则需要该权利. 权利是 com.apple.developer.contacts.notes .您可以使用该权利的请求权限 App Store.

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.

自2019年8月15日起,此权利位于beta类别中,这意味着它可能会在iOS 13发行之前进行更改,并且该权利的名称可能会在向开发人员演示时稳定Xcode.

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.

这篇关于IOS 13 CNContacts不再工作以检索所有联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆