EKEventEditViewController冻结app并在很长时间后加载

时间:2015-05-15 11:53:39

标签: ios swift ekevent ekeventstore ekeventkit

我在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分钟后编辑事件视图控制器出现,有时根本不会。

请帮忙。

1 个答案:

答案 0 :(得分:0)

经过一些挖掘后,我经理要弄清楚eventStore(EKEventStore)变量必须是单例类中的实例变量或全局变量。如果是本地var,则需要永远呈现视图控制器。这可能是SDK上的一些优化问题。