UIDocument openWithCompletionHandler:崩溃 [英] UIDocument openWithCompletionHandler: crash

查看:22
本文介绍了UIDocument openWithCompletionHandler:崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用了 Core Data 并且在下面的代码部分遇到了罕见的崩溃

I'm using Core Data in my project and get a rare crash in the following code section

 -(void) useDocument{
     AFFormsCoreDataEngine* engine = [AFFormsCoreDataEngine sharedInstance];
     if (![[NSFileManager defaultManager] fileExistsAtPath: [engine.formsDatabase.fileURL path]])
     {
         [engine.formsDatabase saveToURL: engine.formsDatabase.fileURL forSaveOperation: UIDocumentSaveForCreating completionHandler: ^(BOOL success){
            // setup
         }];
    }
    else if (engine.formsDatabase.documentState == UIDocumentStateClosed)
    {
        [engine.formsDatabase openWithCompletionHandler: ^(BOOL success){
             // setup
        }];
    }
    else if (engine.formsDatabase.documentState == UIDocumentStateNormal)
    {
         // setup
    }
}

崩溃日志是这样写的:

Last Exception Backtrace:
0   CoreFoundation                  0x371fd88f __exceptionPreprocess + 163
1   libobjc.A.dylib                 0x31272259 objc_exception_throw + 33
2   CoreFoundation                  0x371fd789 +[NSException raise:format:] + 1
3   Foundation                      0x32ce83a3 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 91
4   UIKit                           0x306b3149 -[UIDocument openWithCompletionHandler:] + 173
5   EETECH                          0x00014d23 -[AFFormListViewController useDocument] (AFFormListViewController.m:150)

谁能帮我解决这个问题?这种情况很少发生,但仍然很不愉快

Can anyone help me to solve this issue? It happens very seldom, but still is very unpleasant

推荐答案

如果您的应用尝试连续两次尝试调用您的 useDocument 方法,则会发生错误.

The error occurs if your app attempts to call your useDocument method twice in close succession.

由于openWithCompletionHandler:异步打开文档,再次调用该方法时,文档可能还在打开状态.

Because the openWithCompletionHandler: opens the document asynchronously, the document may still be opening when the method is called again.

如果发生这种情况,您的应用最终会尝试打开文档两次(因为文档状态将保持 UIDocumentStateClosed 直到完成),这会导致抛出异常.

If this happens, your app ends up trying to open the document twice (as the document state will remain UIDocumentStateClosed until completion) and this causes the exception to be thrown.

如果您有异常断点,您可能会在控制台中看到类似这样的内容:

If you have an exception breakpoint, you may see something like this in the console:

 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to open or a revert document that already has an open or revert operation in flight:

这篇关于UIDocument openWithCompletionHandler:崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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