angrycat
angrycat

Reputation: 31

EKEventStore requestAccess() is failing to display the user prompt in iOS 9

I've run into a strange case with requesting Calendar access in iOS 9. The logic works fine on all iOS 10 devices.

In our case, we've added a button on a toolbar that the user taps to add an Event to their Calendar.

So, we don't check for permission to access the calendar until the first time the user taps the "Add to Calendar" button. Like this:

 @IBAction func addToCalendarPressed(_ sender: UIBarButtonItem) {
    eventStore.requestAccess(to: .event, completion: { (granted, error) in
        if (granted) && (error == nil) {
           // Present the EKEventEditViewController
        } else {
           // Do something else (show an alert)
        }
    })
 }

In iOS 10, the app displays the prompt for Calendar access as you'd expect. In iOS 9.x, the prompt doesn't display, the completion handler fires immediately, and granted returns false.

Worse, even though the "Calendar permission" check appears to have completed, you can't go into Settings and manually enable Calendar access. As far as the device is concerned, the app never made the permission check, so the app never appears under Settings > Privacy > Calendar.

I've tried to move the check into viewWillAppear or viewDidLoad instead of waiting for the user to tap the button, and it still doesn't work. I've pulled some sample apps with the event check and they work in iOS 9. I just haven't been able to figure out why the prompt fails in this instance.

The app also checks for location (but not on this screen), and those work correctly in iOS 9.

Upvotes: 1

Views: 1428

Answers (3)

Michal Šrůtek
Michal Šrůtek

Reputation: 2419

If you're using Xcode 15+ and you're targeting iOS 17+, make sure to read the TN3152 document - Migrating to the latest Calendar access levels.

In short, you need to add new plist entries

and call the appropriate method for your use case

the methods also have concurrency counterparts, so you can call them using async/await.

Upvotes: 4

Cwnstantin
Cwnstantin

Reputation: 31

i had similar issue with ios17. The prompt didn't display, the completion handler fired immediately, and granted returns false. i was missing the NSCalendarsFullAccessUsageDescription in the info.plist

eventStore.requestFullAccessToEvents { [weak self] (granted, error) in
    if granted {
        // Access granted
    } else {
        // Access denied
    }
}

Upvotes: 2

angrycat
angrycat

Reputation: 31

We found the issue. Somehow our project didn't have CFBundleDisplayName in the info.plist. At a later point in development, opening the project in Xcode 8 added the property, but left the name blank.

Both the Calendar permission and Photos permission prompts for iOS 9 use that value when displaying the application name in the permission prompt.

The fix was to simply set $(PRODUCT_NAME) for CFBundleDisplayName in our info.plist.

Upvotes: 2

Related Questions