EKEventEditViewController freezes app and loads after long time

ぐ巨炮叔叔 提交于 2019-12-14 03:26:41

问题


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
    }

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.

Please help.


回答1:


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.



来源:https://stackoverflow.com/questions/30258883/ekeventeditviewcontroller-freezes-app-and-loads-after-long-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!