1

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

MplsRich
  • 137
  • 1
  • 13
  • I'm not familiar with PromiseKit but the two arguments to the `requestAccess` completion block are `success` (`Bool`) and `error` (`Error?`). That may affect what you pass to the `resolve` method. – rmaddy Apr 24 '19 at 02:16
  • Thanks rmaddy - PromiseKit (as I understand it) handles the success and error via the .done and .catch closures - in my code the success is yes and the error is no – MplsRich Apr 24 '19 at 14:08

1 Answers1

0

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-

MplsRich
  • 137
  • 1
  • 13