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

by
Maya Patel
axios ekevent ekeventstore ios17 swift-concurrency

Quick Fix: Use ‘requestWriteOnlyAccessToEvents’ method to request access to events with write-only permission. Use ‘requestReadOnlyAccessToEvents’ for read-only permission and ‘requestFullAccessToEvents’ for full access.

The Problem:

I am unable to write EKEvent to the calendar after updating my Xcode to 15.0 and iPhone to iOS 17. The code was previously working without issues. The error message I receive is: Error: -requestAccessToEntityType:completion: has been deprecated-calling this method is no longer allowed.’. I’m trying to access the calendar using the EKEventStore and requestAccess(to: EKEntityType.event). How can I resolve this issue to ensure the code is compatible with iOS 17?

The Solutions:

Solution 1: Handle Compatibility Changes in iOS 17 Calendar Permission Scope

iOS 17 has introduced a new permissions scope for calendar access, breaking compatibility with the previous iOS 16 approach. This leads to errors when you use eventStore.requestAccess() on iOS 17. To address this issue, consider using the following approach:

  1. Use Proper Permission Scope:

    • In iOS 17, access to the user’s calendar is divided into three categories: Read, Write, or Full Access. For most use cases, you will likely need Write or Full Access.
    • If you only require the ability to edit events, you can use the requestWriteOnlyAccessToEvents method. This method has replaced requestAccess in iOS 17.
    • If you require full access to read, edit, and delete events, use the requestFullAccessToEvents method.
  2. Conditional Code Based on iOS Version:

    • To ensure compatibility across different iOS versions, use conditional code based on the iOS version. For example:
    if #available(iOS 17.0, *) {
       eventStore.requestWriteOnlyAccessToEvents { granted, error in
          DispatchQueue.main.async {
             // Write-only access granted or denied logic here
          }
       }
    } else {
       // Previous iOS version code, using requestAccess
    }
    
  3. Handle User Permission Responses:

    • In both cases, handle the permission responses appropriately. If the user denies access, you might want to inform them about the consequences and provide an option to retry or redirect them to the Settings app to grant permission.
  4. Consider EKEventEditViewController:

    • If you use EKEventEditViewController to allow users to create or edit events directly, you don’t need to request any permissions in iOS 17. This is because EKEventEditViewController automatically handles the necessary permissions.
  5. Check Apple’s Documentation:

Q&A

What is the issue with code using eventStore.requestAccess() in iOS?

iOS 17 introduced new permission scopes, causing a deprecation.

How to resolve the error in iOS 17?

Use requestWriteOnlyAccessToEvents() for write access or requestFullAccessToEventsWithCompletion() for full access.