简体   繁体   English

具有EKEvents的PromiseKit-询问用户访问日历事件的许可

[英]PromiseKit with EKEvents - asking user's permission to access calendar events

New to PromiseKit so I want to try it with an async request to get the user's permission to retrieve calendar events. PromiseKit的新功能,因此我想通过异步请求进行尝试,以获得用户检索日历事件的权限。 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: 这是promise的定义:

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. 我通过拒绝应用程序检索日历的权限进行测试-当我授予权限时,代码会打印正确的“被调用”,但是当我拒绝应用程序权限(触发错误,即用户拒绝了应用程序权限)时,我仍然得到“被叫”,当然,Apple会在控制台窗口中抛出错误,无论如何-但是它不会被诺言的“否”部分抓住。

Any help is appreciated 任何帮助表示赞赏

因此,经过更多测试后,Promise无法按以下方式工作,因为如果用户拒绝或接受对日历的访问,则Promise会在“是”上返回true或false-两种情况下的错误均为零-

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM