New to PromiseKit so I want to try it with an async request to get the user's permission to retrieve calendar events. This simple example is just the beginning and will be chaining on from there, but I can't get the first part to work.
Here is the promise definition:
class func retrieveCalendarPermission() -> Promise<Bool> {
return Promise {seal in
EKEventStore().requestAccess(to: .event) {yes, no in
seal.resolve(yes, no)
}
}
}
and here it is implemented:
MyClass.retrieveCalendarPermission().done {yes in
print("yes was called")
}.catch {error in
print ("no was called")
}
I'm testing by denying the app permission to retrieve calendars - when I give permission, the code prints the correct "yes was called" but when I deny the app permission (to trigger the error ie user denied the app permission), I still get the "yes was called" and of course the errors in the console window which Apple throws regardless -but it's not caught by the 'no' part of the promise.
Any help is appreciated
So after a bit more testing, the Promise doesn't work as follows because if the user denies or accepts access to the Calendar, it returns a true or a false on the 'yes' - the error is nil in either case-