首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >EKCalendar标题在iOS12中为空

EKCalendar标题在iOS12中为空
EN

Stack Overflow用户
提问于 2018-09-21 20:08:58
回答 1查看 155关注 0票数 1

在iOS 12中,我试图列出日历。我可以打印日历ids,但是标题都是空的。我做错了什么?

代码语言:javascript
复制
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let status = EKEventStore.authorizationStatus(for: EKEntityType.event)

        switch (status) {
        case EKAuthorizationStatus.notDetermined:
            EKEventStore().requestAccess(to: .event, completion: {
                (granted: Bool, error: Error?) in

                if granted != true {
                    print("Access not granted")
                }
            })
        case EKAuthorizationStatus.authorized:
            print("Access granted")
        case EKAuthorizationStatus.restricted, EKAuthorizationStatus.denied:
            print("Access restricted or denied")
        }

        print("Calendars:")
        for c in EKEventStore().calendars(for: EKEntityType.event) {
            print("    \(c.calendarIdentifier):\(c.title)")
        }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-21 22:24:16

我不知道为什么,但这段代码在iOS 12模拟器中显示了事件标题。

代码语言:javascript
复制
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    let status = EKEventStore.authorizationStatus(for: EKEntityType.event)
    let eventStore = EKEventStore() //<-
    switch (status) {
    case EKAuthorizationStatus.notDetermined:
        eventStore.requestAccess(to: .event, completion: {
            (granted: Bool, error: Error?) in

            if granted != true {
                print("Access not granted")
            }
        })
    case EKAuthorizationStatus.authorized:
        print("Access granted")
    case EKAuthorizationStatus.restricted, EKAuthorizationStatus.denied:
        print("Access restricted or denied")
    }

    print("Calendars:")
    for c in eventStore.calendars(for: EKEntityType.event) {
        print("    \(c.calendarIdentifier):\(c.title)",c)
    }
}

也许,在访问EKEventStore属性时,您需要保持对EKCalendar实例的强烈引用。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52450500

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档