gpt4 book ai didi

macos - 适用于 Mac OS X 10.11 的 CNContact

转载 作者:搜寻专家 更新时间:2023-10-31 22:34:50 25 4
gpt4 key购买 nike

Apple 从 OS X 10.11 和 iOS 9.0 开始提供了这个框架联系人:

https://developer.apple.com/library/prerelease/mac/documentation/Contacts/Reference/Contacts_Framework/index.html#//apple_ref/doc/uid/TP40015328

我想从 Mac 访问联系人,但我无能为力,因为该应用程序无法访问联系人:

switch CNContactStore.authorizationStatusForEntityType(.Contacts) {
case .Authorized:
print("Authorized")
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "contactsAllowed")
case .Denied:
print("Denied")
NSUserDefaults.standardUserDefaults().setBool(false, forKey: "contactsAllowed")
case .NotDetermined:
print("Not Determined")
case .Restricted:
print("Restricted")
}

该应用程序从不提示允许访问联系人,我也不能在系统偏好设置中选择它(它不显示)。

有谁知道如何在 Mac 上访问它们(在 iOS 上运行良好)?

最佳答案

任何对 CNContactStore 实例的调用都应该触发请求。如果不试试

  1. 重新启动(实际上这对我有帮助;我被授予访问权限)
  2. 开启沙盒
  3. 重置隐私设置“sudo tccutil reset AddressBook”
  4. 在主线程中调用

CNContactStore 调用实例:

[[CNContactStore alloc] init];

Privacy

Users can grant or deny access to contact data on a per-application basis. Any call to CNContactStore will block the application while the user is being asked to grant or deny access. Note that the user is prompted only the first time access is requested; any subsequent CNContactStore calls use the existing permissions. To avoid having your app’s UI main thread block for this access, you can use either the asynchronous method [CNContactStore requestAccessForEntityType:CNEntityTypeContacts completionHandler:] or dispatch your CNContactStore usage to a background thread.

关于macos - 适用于 Mac OS X 10.11 的 CNContact,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32300176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com