iOS确保文档在访问前已打开 [英] iOS Make sure documents are open before accessing

查看:84
本文介绍了iOS确保文档在访问前已打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当从关闭状态打开UIDocuments时,我理解它是在另一个线程上完成的。我的问题是,如果我有我的主线程上的代码将访问文档(如执行获取请求),如何保证文档将打开,在我尝试访问之前,如果打开关闭的文档完成异步?

When opening UIDocuments from a closed state, I understand that it is it done on another thread. My question is, if I have code on my main thread that will access the document (like performing a fetch request), how is it guaranteed that the document will be open before I try to access it if the opening of the closed document is done asynchronously?

推荐答案

不要试图阻止一个线程,阻止应用程序的用户访问该文档,直到它打开。这是完成处理程序的用途。

Instead of trying to block a thread, block your application's user from accessing the document until it is open. That's what the completion handler is for.

- (void)openWithCompletionHandler:(void (^)(BOOL success))completionHandler

调用完成处理程序时,只需关闭文档打开时显示的任何临时用户界面。这样,当文档打开时,没有线程被阻塞,并且应用程序保持响应(尽管无用)。

When the completion handler is invoked simply dismiss whatever temporary user interface you display while the document is opening. This way no threads are blocked while the document is opening, and the application remains responsive (albeit useless).

这篇关于iOS确保文档在访问前已打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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