swift - Cannot delete EKCalendar, get Error Domain=EKErrorDomain Code=72
问题描述
I would like to delete an EKCalendar. This works fine on iOS devices and simulators, however trying to get this working on Catalina is problematic. Whatever I try I get this:
Error Domain=EKErrorDomain Code=72 "Can't delete a calendar if doing so would leave the account with no calendars which are eligible to be the default scheduling calendar." UserInfo={NSLocalizedDescription=Can't delete a calendar if doing so would leave the account with no calendars which are eligible to be the default scheduling calendar.}
Any pointers? I have been chasing this for weeks! Thanks!
I have been granted permission for both Calendars and Reminders:
import UIKit
import EventKit
class ViewController: UIViewController {
let eventStore = EKEventStore()
func deleteCal (eventStoreToUse: EKEventStore) {
let calsArray = eventStoreToUse.calendars(for: .event)
for cals in calsArray {
print (cals.title)
if cals.title == "Gaps2" || cals.title == "Done" {
do { try _ = eventStoreToUse.removeCalendar(cals, commit: true)
} catch {
print ("Error \(error)")
}
} else {
print ("Did not delete \(cals.title)")
}
}
}
func askAccess() {
switch EKEventStore.authorizationStatus(for: .event) {
case .authorized:
print ("Calendars Access Granted")
case .denied:
print("Access denied")
case .notDetermined:
eventStore.requestAccess(to: .event, completion:
{[weak self] (granted: Bool, error: Error?) -> Void in
if granted {
print("Granted")
self?.deleteCal(eventStoreToUse: (self?.eventStore)!)
} else {
print("Access denied")
}
})
default:
print("Case default")
}
switch EKEventStore.authorizationStatus(for: .reminder) {
case .authorized:
print ("Reminders Access Granted")
case .denied:
print("Access denied")
case .notDetermined:
eventStore.requestAccess(to: .event, completion:
{[weak self] (granted: Bool, error: Error?) -> Void in
if granted {
print("Granted")
self?.deleteCal(eventStoreToUse: (self?.eventStore)!)
} else {
print("Access denied")
}
})
default:
print("Case default")
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
askAccess()
deleteCal(eventStoreToUse: eventStore)
}
}
解决方案
推荐阅读
- node.js - if 语句 socket io mongodb nodejs
- python - Python、Selenium 和 Chromedriver - 使用 find_element_by_id 的无限循环导致 CPU 问题
- c# - 比较相同枚举类型的对象的枚举
- c# - 通过实体框架中的表名检索表列
- node.js - AWS 使用 JavascriptServices(AspnetCore.NodeServices) 部署 Asp.net-Core 应用程序
- string - 如何用 Fish 计算符号而不是字符串长度?
- perl - 通过 SOAP 访问特定的 OTRS 动态字段值
- caching - Does redis itself have cache?
- swift - 隐藏字段未以 Eureka swift 形式提交其值
- javascript - Deleting multiple child components from parent component in react