EKEventEditViewController长时间冻结应用程序并加载 [英] EKEventEditViewController freezes app and loads after long time

查看:175
本文介绍了EKEventEditViewController长时间冻结应用程序并加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我迅速得到了以下代码:

I have the following code in 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会冻结,有时大约一分钟后会出现编辑事件视图控制器,有时甚至根本没有.

It's pretty straight forward. It works perfectly on simulator. But when you try to run the code on device, the whole UI freezes up and sometimes after about 1 minute the edit event view controller comes up, and sometimes not at all.

请帮助.

推荐答案

经过一番挖掘,我找到了经理来确定eventStore(EKEventStore)变量必须是单例类中的实例变量或全局变量.如果它是本地变量,那么将永远需要显示视图控制器.这可能是SDK上的一些优化问题.

After a bit of digging I've manager to figure out that the eventStore (EKEventStore) variable must be an instance variable or a global var in a singleton class. If it is a local var it will take forever to present the view controller. This is probably some optimisation issues on the SDK.

这篇关于EKEventEditViewController长时间冻结应用程序并加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆