Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

requestAccessToEntityType:completion: has been deprecated calling this is no longer allowed. Instead use requestFullAccessToEventsWithCompletion:

Today, I have updated my Xcode to 15.0 and my iPhone to iOS 17, but now my code that writes EKEvent in the calendar does not work anymore. It was working fine in earlier versions of iOS. Do I have a compatibility issue or is there another reason?

The error is this:

Error: -requestAccessToEntityType:completion: has been deprecated-calling this method is no longer allowed. Instead, use -requestFullAccessToEventsWithCompletion:, -requestWriteOnlyAccessToEventsWithCompletion:, or -requestFullAccessToRemindersWithCompletion:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My code looks like this below snippet:

    func accesCalenderToAddEvent() {
        let eventStore: EKEventStore = EKEventStore()
        eventStore.requestAccess(to: EKEntityType.event) { granted, error in
            DispatchQueue.main.async {
                if (granted) && (error == nil) {
                    let event = EKEvent(eventStore: self.eventStore)
                    event.title = "Event 1"
                    event.startDate = Date()
                    event.endDate = Date()
                    
                    let eventController = EKEventEditViewController()
                    eventController.event = event
                    eventController.eventStore = eventStore
                    eventController.editViewDelegate = self
                    self.present(eventController, animated: true, completion: nil)
                } else {
                    let alertController = UIAlertController(title: "Calendar Permission Required", message: "Please enable Calender permissions in settings.", preferredStyle: UIAlertController.Style.alert)
                    let okAction = UIAlertAction(title: "OK", style: .default, handler: {(cAlertAction) in
                        //Redirect to Settings app
                        UIApplication.shared.open(URL(string:UIApplication.openSettingsURLString)!)
                    })
                    alertController.addAction(okAction)
                    self.present(alertController, animated: true, completion: nil)
                }
            }
        }
    }

Please suggest me the solution for iOS 17 because in earlier version it’s work for me.

Thanks in advance.

>Solution :

The permissions scope for iOS 17 has changed to include Read, write, and full access, unlike iOS 16 which only had full access. This causes an error when you use eventStore.requestAccess() on iOS 17, but not on iOS 16.

Deprecation notice: https://developer.apple.com/documentation/eventkit/ekeventstore/1507547-requestaccesstoentitytype

More info: https://developer.apple.com/documentation/eventkit/ekeventstore/4162272-requestfullaccesstoeventswithcom

To provide support in iOS 17 write code like the below:

if #available(iOS 17.0, *) {
    eventStore.requestWriteOnlyAccessToEvents { granted, error in
        DispatchQueue.main.async {
            //write the existing logic here
        }
    }
}else {
    //put the old code here so it’s been working in earlier versions before iOS 17.
}

Note:

If you are only using EKEventEditViewController then you no need
to take the any permission as per this official doc: Documentation

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading