热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

日历列表快速返回空数组

我正在尝试获取日历事件和提醒,但有些却不返回事件,提醒,日历,事件源的

我正在尝试获取日历事件和提醒,但有些却不返回事件,提醒,日历,事件源的列表。我已获得访问事件的权限,但即使获得许可,我也无法获取数据。但是,如果我去设置并尝试打开和关闭日历权限,那么我将成功获取所有数据。以下是我发送的代码,如果我输入错误,请提出建议。

func requestaccessToCalendar() {
self.eventStore.requestaccess(to: EKEntityType.event) { (accessGranted,error) in
if accessGranted == true {
DispatchQueue.main.async(execute: {
self.isAuthorized = true
let application = UIApplication.shared
application.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
self.authorizationCompletionHandler!(true,.authorized)
})
} else {
DispatchQueue.main.async(execute: {
self.isAuthorized = false
self.authorizationCompletionHandler!(false,.denied)
})
}
}
}
let status = EKEventStore.authorizationStatus(for: EKEntityType.event)
if status == .authorized {
// let startDate = Date()
// let endDate = Date().dateSixtyDaysAfter()
let startDate = self.calendarDates().0//It return me the date of two months ago
let endDate = self.calendarDates().1 // Return todays date.
let calendars = self.eventStore.calendars(for: .event)
print("calendars: \(calendars)")//Here i get empty list of calendar even i have 26 calendar in device.
let eventsPredicate = self.eventStore.predicateForEvents(withStart: startDate!,end: endDate!,calendars: nil)
self.events = self.eventStore.events(matching: eventsPredicate)
var eventInfoList = [[String: AnyObject]]()
if let events = self.events {
for event in events {
//Here i did some operation on calendar event
}
} else {
print("No calendar and data found")
}
} else {
print("Don't have calendar access")
}





推荐阅读
author-avatar
mizrke
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有