gpt4 book ai didi

objective-c - NSSavePanel 在沙盒应用程序 OS X 10.10 中崩溃

转载 作者:行者123 更新时间:2023-12-03 17:02:37 27 4
gpt4 key购买 nike

我在沙盒应用程序中使用 OS X 10.10 中的 NSSavePanel 来让用户选择文件的保存位置(非常标准),但是当我调用时应用程序崩溃了:

NSSavePanel *panel = [NSSavePanel savePanel];

我在调试器中得到了这个:

2014-10-14 18:22:16.019 Farm Hand[2807:942766] an error occurred while attempting to connect to listener 'com.apple.view-bridge': Connection interrupted
2014-10-14 18:22:16.020 Farm Hand[2807:942766] *** Assertion failure in +[NSXPCSharedListener connectionForListenerNamed:fromServiceNamed:], /SourceCache/ViewBridge/ViewBridge-99/NSXPCSharedListener.m:394
2014-10-14 18:22:16.023 Farm Hand[2807:942766] An uncaught exception was raised
2014-10-14 18:22:16.023 Farm Hand[2807:942766] NSXPCSharedListener unable to create endpoint for listener named com.apple.view-bridge
2014-10-14 18:22:16.023 Farm Hand[2807:942766] (
0 CoreFoundation 0x00007fff8880364c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff9390e6de objc_exception_throw + 43
2 CoreFoundation 0x00007fff8880342a +[NSException raise:format:arguments:] + 106
3 Foundation 0x00007fff8a3a65b9 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 ViewBridge 0x00007fff964e40b8 +[NSXPCSharedListener connectionForListenerNamed:fromServiceNamed:] + 151
5 ViewBridge 0x00007fff964c2981 -[NSRemoteViewBase serviceMarshalConnection] + 286
6 ViewBridge 0x00007fff964c36ae -[NSRemoteViewBase advanceToConfigPhase:awaitingWindowRights:] + 414
7 ViewBridge 0x00007fff964d1f7b -[NSWindowCentricRemoteView advanceToConfigPhase] + 947
8 ViewBridge 0x00007fff964c4223 -[NSRemoteViewBase viewServiceMarshalProxy:withErrorHandler:] + 88
9 ViewBridge 0x00007fff964ba8a8 -[NSRemoteViewBase bridge] + 207
10 AppKit 0x00007fff8e859b9d -[NSVBSavePanel init] + 303
11 AppKit 0x00007fff8e5a8ec1 +[NSSavePanel newRemotePanel] + 301
12 AppKit 0x00007fff8e5a8f53 +[NSSavePanel _crunchyRawUnbonedPanel] + 74
13 Farm Hand 0x000000010009526d __40-[RHFlockHomeViewController exportTable]_block_invoke_3 + 109
14 libdispatch.dylib 0x00000001002202bb _dispatch_call_block_and_release + 12
15 libdispatch.dylib 0x000000010021ad43 _dispatch_client_callout + 8
16 libdispatch.dylib 0x0000000100229d9f _dispatch_main_queue_callback_4CF + 1370
17 CoreFoundation 0x00007fff88756c59 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
18 CoreFoundation 0x00007fff887132ef __CFRunLoopRun + 2159
19 CoreFoundation 0x00007fff88712838 CFRunLoopRunSpecific + 296
20 HIToolbox 0x00007fff94ec743f RunCurrentEventLoopInMode + 235
21 HIToolbox 0x00007fff94ec71ba ReceiveNextEventCommon + 431
22 HIToolbox 0x00007fff94ec6ffb _BlockUntilNextEventMatchingListInModeWithFilter + 71
23 AppKit 0x00007fff8e006821 _DPSNextEvent + 964
24 AppKit 0x00007fff8e005fd0 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 194
25 AppKit 0x00007fff8dff9f73 -[NSApplication run] + 594
26 AppKit 0x00007fff8dfe5424 NSApplicationMain + 1832
27 Farm Hand 0x0000000100010552 main + 34
28 libdyld.dylib 0x00007fff8d7e85c9 start + 1
)
2014-10-14 18:22:16.027 Farm Hand[2807:942766] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSXPCSharedListener unable to create endpoint for listener named com.apple.view-bridge'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff8880364c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff9390e6de objc_exception_throw + 43
2 CoreFoundation 0x00007fff8880342a +[NSException raise:format:arguments:] + 106
3 Foundation 0x00007fff8a3a65b9 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 ViewBridge 0x00007fff964e40b8 +[NSXPCSharedListener connectionForListenerNamed:fromServiceNamed:] + 151
5 ViewBridge 0x00007fff964c2981 -[NSRemoteViewBase serviceMarshalConnection] + 286
6 ViewBridge 0x00007fff964c36ae -[NSRemoteViewBase advanceToConfigPhase:awaitingWindowRights:] + 414
7 ViewBridge 0x00007fff964d1f7b -[NSWindowCentricRemoteView advanceToConfigPhase] + 947
8 ViewBridge 0x00007fff964c4223 -[NSRemoteViewBase viewServiceMarshalProxy:withErrorHandler:] + 88
9 ViewBridge 0x00007fff964ba8a8 -[NSRemoteViewBase bridge] + 207
10 AppKit 0x00007fff8e859b9d -[NSVBSavePanel init] + 303
11 AppKit 0x00007fff8e5a8ec1 +[NSSavePanel newRemotePanel] + 301
12 AppKit 0x00007fff8e5a8f53 +[NSSavePanel _crunchyRawUnbonedPanel] + 74
13 Farm Hand 0x000000010009526d __40-[RHFlockHomeViewController exportTable]_block_invoke_3 + 109
14 libdispatch.dylib 0x00000001002202bb _dispatch_call_block_and_release + 12
15 libdispatch.dylib 0x000000010021ad43 _dispatch_client_callout + 8
16 libdispatch.dylib 0x0000000100229d9f _dispatch_main_queue_callback_4CF + 1370
17 CoreFoundation 0x00007fff88756c59 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
18 CoreFoundation 0x00007fff887132ef __CFRunLoopRun + 2159
19 CoreFoundation 0x00007fff88712838 CFRunLoopRunSpecific + 296
20 HIToolbox 0x00007fff94ec743f RunCurrentEventLoopInMode + 235
21 HIToolbox 0x00007fff94ec71ba ReceiveNextEventCommon + 431
22 HIToolbox 0x00007fff94ec6ffb _BlockUntilNextEventMatchingListInModeWithFilter + 71
23 AppKit 0x00007fff8e006821 _DPSNextEvent + 964
24 AppKit 0x00007fff8e005fd0 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 194
25 AppKit 0x00007fff8dff9f73 -[NSApplication run] + 594
26 AppKit 0x00007fff8dfe5424 NSApplicationMain + 1832
27 Farm Hand 0x0000000100010552 main + 34
28 libdyld.dylib 0x00007fff8d7e85c9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

这是我的完整代码:

if ([format isEqualToString:@".csv"]) {
loadingBar = [RHLoadingBar loadingBarWithMessage:@"Preparing File..."];
[loadingBar showModally];
[loadingBar start];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *string = [[RHFileController sharedController] CSVTableWithObject:sheepArrayController.arrangedObjects propertyKeys:@[@"tagNumber", @"ukNumber", @"age", @"breed", @"comments"] columnHeaders:@[@"Tag Number", @"UK Number", @"Age", @"Breed", @"Comments"]];
dispatch_async(dispatch_get_main_queue(), ^{
[loadingBar stop];
[loadingBar dismiss];
NSSavePanel *panel = [NSSavePanel savePanel];
[panel beginSheetModalForWindow:[[NSApplication sharedApplication] mainWindow] completionHandler:^(NSInteger result) {

}];
});
});
}

这是一个已知的错误还是我的代码中的某些错误?如果这是一个已知的错误,我可以绕过它。

  • 编辑:这就是我解决这个问题的方法,直到 Apple 修复它(感谢 @serren 修复):

首先取消选中主窗口 Controller 中的Is Initial Controller(您的应用现在不会自动启动主窗口)。

然后:

AppDelegate.h中:

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>
// Add strong reference to the root window controller
@property (strong) NSWindowController *rootController;


@end

最后在 AppDelegate.m 中实现 applicationDidFinishLaunching: 像这样(记住设置你的初始 Controller 标识符,这里我的是“HomeView”):

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
// Show main window (to avoid powerbox bug)...
NSStoryboard *sb = [NSStoryboard storyboardWithName:@"Main" bundle:nil];
rootController = [sb instantiateControllerWithIdentifier:@"HomeView"];
[rootController showWindow:self];

// Other custom setup for your App...
}

此过程意味着 NSApplicationmainWindow 属性将自动设置为 rootController.window。因此,如果您想随时获取主窗口,您仍然可以调用 [[NSApplication sharedApplication] mainWindow]; 还有 AppDelegateNSApplication 单例都对该窗口有强引用,这一点很重要(否则窗口将被释放,应用程序将崩溃)。

希望这暂时能有所帮助。

最佳答案

不幸的是,上面的答案与我的场景无关,因为创建 NSSavePanel 的屏幕上没有 ArrayController。

对原始问题的评论之一为我指出了正确的方向,即摆脱自定义 WindowController 子类。当我这样做时,面板看起来很好。然而,由于这不是一个很好的解决方案(如果你真的想保留你的自定义类),我继续挖掘..

仅供引用,我正在使用 NSStoryboards 并为 10.10 构建应用程序。

当我(暂时)取消选中主窗口上的“可恢复”时,我注意到一些奇怪的行为 - 每次出现保存面板时,我的应用程序都会出现一个新的主窗口。这让我相信我的应用程序委托(delegate)与显示的主窗口存在重大脱节 - 特别是现在 Storyboard具有单独的应用程序场景和 WindowController。

我做了什么:

  1. 选择我的主窗口 Controller 并取消选中“是初始 Controller ”(即没有为 Storyboard设置初始 Controller )
  2. 在我的应用程序委托(delegate)中,在 applicationDidFinishLaunching: 中,我手动创建了 Storyboard并使用 instantiateControllerWithIdentifier: 加载了窗口 Controller
  3. 我将 self.window 设置为创建的 windowController.window 属性
  4. 我将 self.window 设置为 key 和订单前端(使用 makeKeyAndOrderFront:)

应用程序启动,像以前一样加载窗口,但现在保存面板显示得很好。它还可以与自定义 windowController 子类一起使用。

最后,作为奖励,我在使用 applicationShouldTerminateAfterLastWindowClosed 时终于有了正确的行为(被设置为 NO)

关于objective-c - NSSavePanel 在沙盒应用程序 OS X 10.10 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26366711/

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