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
}
EventModel
? – Montespan