我之前看过一个类似这样的问题,但答案是不需要许可,因为没有编辑......但是关于为什么没有显示用户提示的问题没有得到回答。
我的问题是我确实需要编辑,所以确实需要这个提示,以便用户可以授予权限。目前,我没有收到提示,因此访问总是“被拒绝”。
我的片段如下。(Xcode 7.2.1 iOS 9.2.1)任何帮助,提示将不胜感激。我没有看到任何其他有此问题的人,所以不知道问题是什么...我尝试了已弃用的 AB 方法以及相同的 NO 权限提示...是否有一些 plist 字符串需要设置为位置经理???
谢谢...
func checkContactsAccess() {
switch CNContactStore.authorizationStatusForEntityType(.Contacts) {
// Update our UI if the user has granted access to their Contacts
case .Authorized:
print("Access Granted")
// Prompt the user for access to Contacts if there is no definitive answer
case .NotDetermined :
self.requestContactsAccess()
// Display a message if the user has denied or restricted access to Contacts
case .Denied,
.Restricted:
let alert = UIAlertController(title: "Privacy Warning!",
message: "Permission was not granted for Contacts.",
preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
func requestContactsAccess() {
contactStore.requestAccessForEntityType(.Contacts) {granted, error in
if granted {
dispatch_async(dispatch_get_main_queue()) {
print("Access Granted")
return
}
}
}
}