Why use dispatch_async when using performSegueWithIdentifier in requestAccessToEntity:completion?

旧城冷巷雨未停 提交于 2020-01-24 10:02:07

问题


When I call the performSegueWithIdentifier in the completion block, if I do not wrap the call in a dispatch_async, it literally takes 10 seconds for the segue to actually happen. However, I can do other things without wrapping them in the same dispatch_async, such as doing core data work, or, logging "things"...

Any insight as to how this works and why... I am lost. If this isn't the right place to ask something like this, I apologize.

EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self performSegueWithIdentifier:self.phaseSegue sender:self];
    });
}];

回答1:


From the documentation:

When the user taps to grant or deny access, the completion handler will be called on an arbitrary queue.

Also, all UI-related stuff must be done on the main queue. That's way you need that dispatch_async.



来源:https://stackoverflow.com/questions/22315313/why-use-dispatch-async-when-using-performseguewithidentifier-in-requestaccesstoe

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