iOS Make sure documents are open before accessing

时光毁灭记忆、已成空白 提交于 2019-12-02 10:26:11

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).

You should use documentState property of UIDocument class. For more detail refer this document documentState description.

It returns following enumerators to check:

enum {
    UIDocumentStateNormal          = 0,
    UIDocumentStateClosed          = 1 << 0,
    UIDocumentStateInConflict      = 1 << 1,
    UIDocumentStateSavingError     = 1 << 2,
    UIDocumentStateEditingDisabled = 1 << 3   }; typedef NSInteger UIDocumentState;

From Description: UIDocumentStateNormal is what you want, as:
The document is open, editing is enabled, and there are no conflicts or errors associated with it.

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