I have tried the earlier examples of asking permission to add items to the IOS calendar. They do not work with Xcode 10.1 (Swift 4.2). When I try to compile the code, I get an error. If I comment out the lines beginning with "EKEventstore.requestAccess", the code executes the ".not.Determined" loop.
The error is "Instance member 'requestAccess' cannot be used on type 'EKEventStore'; did you mean to use a value of this type instead?"
Can anyone please find my error so that the IOS app can have permission to add events to the Calendar?
func SOGetPermissionCalendarAccess() {
switch EKEventStore.authorizationStatus(for: .event) {
case .authorized:
print("Authorized")
case .denied:
print("Access denied")
case .notDetermined:
EKEventStore.requestAccess(to: .event, completion:
{[weak self] (granted: Bool, error: Error?) -> Void in
if granted {
print("Access granted")
} else {
print("Access denied")
}
})
print("Not Determined")
default:
print("Case Default")
}
}
You should create event store instance as like below,
let eventStore = EKEventStore()
After that you can make permission request as like below,
switch EKEventStore.authorizationStatus(for: .event) {
case .authorized:
print("Authorized")
case .denied:
print("Access denied")
case .notDetermined:
eventStore.requestAccess(to: .event, completion:
{(granted: Bool, error: Error?) -> Void in
if granted {
print("Access granted")
} else {
print("Access denied")
}
})
print("Not Determined")
default:
print("Case Default")
}
Please refer this link for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With