gpt4 book ai didi

ios - requestAccessForEntityType 不提示用户

转载 作者:行者123 更新时间:2023-11-29 00:49:54 25 4
gpt4 key购买 nike

我尝试使用下面的代码访问手机联系人,但系统不会提示用户授予我权限。

 let store = CNContactStore()
store.requestAccessForEntityType(.Contacts) { granted, error in
guard granted else {
dispatch_async(dispatch_get_main_queue()) {
// user didn't grant authorization, so tell them to fix that in settings
print("error accessing adress book %@",error)
}
return
}
print("Access granted to adress book")
// get the contacts

var contacts = [CNContact]()
let request = CNContactFetchRequest(keysToFetch: [CNContactIdentifierKey, CNContactFormatter.descriptorForRequiredKeysForStyle(.FullName)])
do {
try store.enumerateContactsWithFetchRequest(request) { contact, stop in
contacts.append(contact)
}
} catch {
print(error)
}

//TODO : Do something with the contacts
let formatter = CNContactFormatter()
formatter.style = .FullName
for contact in contacts {
print(formatter.stringFromContact(contact))
}
}

最佳答案

您能否详细说明确切的错误是什么?

我在 iOS 9.2.1 设备上试过你的代码,代码似乎工作正常。我得到了“地址簿的访问权限”日志和联系人信息。

如果您遇到 Error Domain=CNErrorDomain Code=100 “Access Denied” 错误,您应该在“设置”->“隐私”->“通讯录”中检查设备权限。

以防万一,如果您在联系人访问权限提示上单击了“不允许”,现在由于首选项已保存并且您没有收到提示,那么您可以更改您的包标识符以测试您的代码。

如果您需要重置所有隐私设置:https://stackoverflow.com/a/12596350/4209778

关于ios - requestAccessForEntityType 不提示用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38267329/

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