我在我的项目中使用了核心数据,并且在下面的代码部分中遇到了罕见的崩溃
-(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)有人能帮我解决这个问题吗?这种情况很少发生,但仍然非常令人不快。
发布于 2012-09-08 03:15:06
如果您的应用程序尝试连续两次调用您的useDocument方法,则会发生此错误。
因为openWithCompletionHandler:异步打开文档,所以再次调用该方法时文档可能仍处于打开状态。
如果发生这种情况,您的应用程序最终会尝试打开文档两次(因为文档状态将保持为UIDocumentStateClosed,直到完成),这会导致抛出异常。
如果您有一个异常断点,您可能会在控制台中看到类似以下内容:
*** 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:发布于 2012-08-14 08:11:18
那么,断言在UIDocument代码中失败了。您可能应该提供更多的代码,因为您显然设置了一些不正确的东西。
然后,断言抛出一个异常。如果你在这个方法中@catch异常,你可以记录异常。
或者,您可以将自己的NSAssertionHandler分配给线程,并直接查看断言。
https://stackoverflow.com/questions/11933055
复制相似问题