仅在 MacOS 10.15 中,仅在尝试将文件两次保存到同一目录时,并且仅在打开 NSOpenPanel 之后点击取消或打开。我的应用程序因以下堆栈跟踪而挂起,并且该应用程序无法恢复,我不得不将其杀死。
*** -[NSSavePanel _attachSandboxExtensions:toURL:orURLs:]、/BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1894.30.142/Nav.subproj/OpenAndSavePanelRemote/NSVBOpenAndSavePanels.m 中的断言失败: 711 -[NSSavePanel observeValueForKeyPath:ofObject:change:context:] 捕获非致命 NSInternalInconsistencyException '沙盒扩展字符串的意外类类型!' 带回溯(
0 CoreFoundation 0x00007fff2bc5c8ab __exceptionPreprocess + 250
1 libobjc.A.dylib 0x00007fff61f16805 objc_exception_throw + 48
2 CoreFoundation 0x00007fff2bc85d10 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff2e37e241 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 AppKit 0x00007fff297987b2 __53-[NSSavePanel _attachSandboxExtensions:toURL:orURLs:]_block_invoke + 240
5 CoreFoundation 0x00007fff2bbd4037 __NSARRAY_IS_CALLING_OUT_TO_A_BLOCK__ + 7
6 CoreFoundation 0x00007fff2bbeac36 -[__NSSingleObjectArrayI enumerateObjectsWithOptions:usingBlock:] + 80
7 AppKit 0x00
有没有人有同样的问题和解决方案?
这是我用来保存文件的代码:
@IBAction func saveAct(_ sender: Any) {
let savePanel = NSSavePanel()
defaultPath = UserDefaultUtil.pathDir
savePanel.directoryURL = URL(fileURLWithPath: defaultPath)
savePanel.nameFieldStringValue = "export"
savePanel.allowedFileTypes = ["jpeg"]
savePanel.accessoryView = accessoryView
// <--------------- Assertion failure HERE (the beginSheetModal not called)
savePanel.beginSheetModel(for: self.view.window!, completionHandler: {(num) -> Void in
if num == .OK {
....
}else{
....
}
})
}