I’m building an iOS App that creates programatically events in the iOS Calendar.
My code works perfectly when run in any iOS Simulator. But then when installled in any physical device, it simply doesn’t. What am I doing wrong?
When calling the requestAccess() function, either on the onAppear method, or inside a button, it doesn’t work. It seems to be an authentication issue, but no reason why it does work in the simulator and not in physical device.
Has anyone faced the same issue?
Any thoughts? Or recommendation?
import Foundation
import EventKit
class EventModel {
let eventStore = EKEventStore()
let todayDate : Date = Date()
func requestAccess() {
let status = EKEventStore.authorizationStatus(for: .event)
if status == .authorized {
print("Access is already granted.")
} else {
print(status.rawValue)
eventStore.requestFullAccessToEvents { success, error in
if success && error == nil {
print("Access has been granted.")
} else {
print(error)
print("Access request failed with error: (error?.localizedDescription ?? "Unknown error")")
}
}
}
}
//more code and other stuff
}
2
Answers
I was able to resolve this same issue in our app – for us the cause was that we hand’t updated our
info.plist
.We needed to add entry(ies) for the new calendar permissions from iOS 17. Depending on your particular case, you’ll need to add one/both of these:
Please note you’ll probablt also need to keep the old
NSCalendarsUsageDescription
entry so that things still work on older versions of iOS.Hope this helps!
We dont need to add — latest functions for iOS-17 as it introduces requestFullAccessToEvents.
Solution that worked is to add two keys in Info.plist file including previous key i.e. NSCalendarsUsageDescription