gpt4 book ai didi

ios - UIDocument openWithCompletionHandler : crash

转载 作者:可可西里 更新时间:2023-11-01 06:19:01 24 4
gpt4 key购买 nike

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

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

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

最佳答案

如果您的应用尝试连续两次调用您的 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:

关于ios - UIDocument openWithCompletionHandler : crash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11933055/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com