我在swift中有以下代码:
var eventController = EKEventEditViewController()
eventController.editViewDelegate = self
var store = EKEventStore()
eventController.eventStore = store
var event = EKEvent(eventStore: store)
event.title = viewModel.roleName
event.location = viewModel.location
event.startDate = viewModel.startDate
event.endDate = viewModel.endDate
eventController.event = event
var status = EKEventStore.authorizationStatusForEntityType(EKEntityTypeEvent)
switch status {
case .Authorized:
self.setNavBarAppearanceStandard()
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.presentViewController(eventController, animated: true, completion: nil)
})
case .NotDetermined:
store.requestAccessToEntityType(EKEntityTypeEvent, completion: { (granted, error) -> Void in
if granted == true {
self.setNavBarAppearanceStandard()
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.presentViewController(eventController, animated: true, completion: nil)
})
}
})
case .Denied, .Restricted:
UIAlertView(title: "Access Denied", message: "Permission is needed to access the calendar. Go to Settings > Privacy > Calendars to allow access for the Be Collective app.", delegate: nil, cancelButtonTitle: "OK").show()
return
}
这很直接。它在模拟器上完美运行。但是,当您尝试在设备上运行代码时,整个UI会冻结,有时大约1分钟后编辑事件视图控制器出现,有时根本不会。
请帮忙。
答案 0 :(得分:0)
经过一些挖掘后,我经理要弄清楚eventStore(EKEventStore)变量必须是单例类中的实例变量或全局变量。如果是本地var,则需要永远呈现视图控制器。这可能是SDK上的一些优化问题。