如果用户拒绝访问日历,我会尝试弹出“转到设置”警报。一旦用户拒绝日历并重新打开应用程序,它就会起作用。但我需要在用户拒绝访问后立即弹出警报。
这是我的日历访问代码:
/**
*/
func requestDeniedAlert() -> UIAlertController {
let requestAlertController = UIAlertController(title: "Calendar Access Denied", message: "Please Allow Calendar Access In Settings", preferredStyle: .alert)
let settingsAction = UIAlertAction(title: "Go To Settings", style: .default){(action) in
print("The User Will Be Taken To the Settings")
let goToSettings = URL(string: UIApplicationOpenSettingsURLString)
UIApplication.shared.open(goToSettings!)
}
requestAlertController.addAction(settingsAction)
return requestAlertController
}
/**
reuestCalendarPermissions:
@param
@return
*/
func requestCalendarPermissions() {
eventInstance.requestAccess(to: .event, completion: {(accessGranted: Bool, error: Error?) in
if accessGranted == true {
print("Access Has Been Granted")
MainScreenTableView.flagVariable.statusFlag = true
}
else {
print("Change Settings to Allow Access")
MainScreenTableView.flagVariable.statusFlag = false
}
})
}
/**
checkStatus:
Notes: This function checks if the User has given calendar access to app
If access is restricted or denied, a "Go To Settings" view will appear
*/
func checkStatus() {
let currentStatus = EKEventStore.authorizationStatus(for: EKEntityType.event)
if currentStatus == EKAuthorizationStatus.notDetermined {
requestCalendarPermissions()
}
else if currentStatus == EKAuthorizationStatus.authorized {
print("Access Has Been Granted")
MainScreenTableView.flagVariable.statusFlag = true
}
else if (currentStatus == EKAuthorizationStatus.denied) || (currentStatus == EKAuthorizationStatus.restricted){
print("Access Has Been Denied")
MainScreenTableView.flagVariable.statusFlag = false
}
}
我正在使用 UITableViewController ,这似乎是让这变得如此痛苦的原因。我现在的方式是设置一个标志,然后在表格 View 中显示警报。但我无法在用户拒绝访问后立即弹出警报。
感谢您的帮助!
最佳答案
简单的解决方案是在 accessGranted == false
时从调用 eventInstance.requestAccess
的完成处理程序内部显示警报。
accessGranted
将为 false
。
关于ios - 如果日历访问被拒绝,则显示警报 Swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41247431/