Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 无法删除EKCalendar,获取错误域=EKErrorDomain代码=72_Swift_Ekcalendar - Fatal编程技术网

Swift 无法删除EKCalendar,获取错误域=EKErrorDomain代码=72

Swift 无法删除EKCalendar,获取错误域=EKErrorDomain代码=72,swift,ekcalendar,Swift,Ekcalendar,我想删除一个日历。这在iOS设备和模拟器上运行良好,但是在Catalina上尝试实现这一点是有问题的。无论我尝试什么,我都会得到: Error Domain=EKErrorDomain Code=72“如果执行以下操作,则无法删除日历” 因此,您会将帐户保留为没有符合条件的日历 默认的日程安排日历。“ UserInfo={NSLocalizedDescription=如果这样做,则无法删除日历 将使帐户没有符合条件的日历 默认计划日历。} 有什么建议吗?我已经追了好几个星期了!谢谢 我已被授予日

我想删除一个日历。这在iOS设备和模拟器上运行良好,但是在Catalina上尝试实现这一点是有问题的。无论我尝试什么,我都会得到:

Error Domain=EKErrorDomain Code=72“如果执行以下操作,则无法删除日历” 因此,您会将帐户保留为没有符合条件的日历 默认的日程安排日历。“ UserInfo={NSLocalizedDescription=如果这样做,则无法删除日历 将使帐户没有符合条件的日历 默认计划日历。}

有什么建议吗?我已经追了好几个星期了!谢谢

我已被授予日历和提醒的权限:

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)
    }
}