NSSavePanel崩溃在沙盒应用程序OS X 10.10 [英] NSSavePanel crash in sandbox app OS X 10.10

查看:1569
本文介绍了NSSavePanel崩溃在沙盒应用程序OS X 10.10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  NSSavePanel * panel = [NSSavePanel savePanel]; 

我在调试器中得到这个:

  2014-10-14 18:22:16.019 Farm Hand [2807:942766]尝试连接到侦听器com.apple.view-bridge时出错:连接中断
2014-10-14 18:22:16.020 Farm Hand [2807:942766] ***在+ [NSXPCSharedListener connectionForListenerNamed:fromServiceNamed:]中发生声明失败,/SourceCache/ViewBridge/ViewBridge-99/NSXPCSharedListener.m:394
2014-10-14 18:22:16.023 Farm Hand [2807:942766]引发了未捕获的异常
2014-10-14 18:22:16.023 Farm Hand [2807:942766] NSXPCSharedListener无法创建端点监听器名为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基础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桥] + 207
10 AppKit的0x00007fff8e859b9d - [ NSVBSavePanel的init] + 303
11 AppKit的0x00007fff8e5a8ec1 + NSSavePanel newRemotePanel] + 301
12 AppKit的0x00007fff8e5a8f53 + NSSavePanel _crunchyRawUnbonedPanel] + 74
13雇农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:离队:] + 194
25 AppKit的0x00007fff8dff9f73 - [的NSApplication运行] + 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] ***由于未捕获异常NSInternalInconsistencyException而终止应用程序,原因:'NSXPCSharedListener无法为名为com.apple.view-bridge的监听器创建端点
***第一次调用堆栈:

0 CoreFoundation 0x00007fff8880364c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff9390e6de objc_exception_throw + 43
2 CoreFoundation 0x00007fff8880342a + [NSException raise:format:arguments:] + 106
3基础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桥] + 207
10 AppKit的0x00007fff8e859b9d - [NSVBSavePanel的init] + 303
11 AppKit的0x00007fff8e5a8ec1 + NSSavePanel newRemotePanel] + 301
12 AppKit的0x00007fff8e5a8f53 + NSSavePanel _crunchyRawUnbonedPanel] + 74
13雇农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:以NSException类型的未捕获异常结束

这是我的代码:

  if([format isEqualToString:@。csv]){
loadingBar = [RHLoadingBar loadingBarWithMessage:@准备文件...
[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){

}];
});
});
}

这是一个已知的错误还是在我的代码?




  • 编辑:这是我解决它,直到苹果解决它(谢谢到@serren的修复):



首先取消选中是初始控制器



然后:



AppDelegate.h 中:

  #import <可可。 

@interface AppDelegate:NSObject< NSApplicationDelegate>
//添加对根窗口控制器的强引用
@property(strong)NSWindowController * rootController;


@end

最后在 AppDelegate.m 实现 applicationDidFinishLaunching:这样(记得设置你的初始控制器标识符,这里我是HomeView):

   - (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
{
//在此处插入代码以初始化应用程序
//显示主窗口(避免powerbox bug)...
NSStoryboard * sb = [NSStoryboard storyboardWithName:@Mainbundle:nil];
rootController = [sb instantiateControllerWithIdentifier:@HomeView];
[rootController showWindow:self];

//您的应用程序的其他自定义设置...
}

此过程将意味着 NSApplication mainWindow 属性将设置为 rootController.window 。所以如果你想在任何时候得到你的主窗口,你仍然可以调用 [[NSApplication sharedApplication] mainWindow]; 还有 AppDelegate NSApplication singleton都有一个强烈的引用这个窗口是重要的(否则窗口将被释放,应用程序将崩溃)。

$

解决方案

简短描述: / strong>



这看起来像是一个与ArrayController有关的错误,也许是任何其他类似的控制器,或者它继承的或者IB中的绑定系统。以下是一个简单的代码,详细说明了问题: https:// www .dropbox.com / s / atwoc2hweh5fjk6 / Bug.zip?dl = 0



详细说明: b
$ b

看起来很奇怪,在SDK里面有些奇怪。



在我提供的例子中,我有一个标准的应用程序使用标准Xcode 6.1模板生成。应用程序是沙箱。在应用程序代理中,我们简单地测试NSSavePanel是否会在没有任何问题的情况下触发。 ViewController声明一个名为array的属性,后来绑定到一个NSArrayController(见Main.storyboard里面)。



如果你在这个设置中启动应用程序, NSSavePanel失败。但是,如果我们简单地关闭NSArrayController绑定,对NSSavePanel的调用就会奇迹般地起作用。



因此,可以假定这只是一个隐藏在下面的坏bug最新的SDK,苹果需要修复。



随时可以将示例添加到您向Apple提交的错误报告中。



Wokround:



看起来如果禁用数组控制器绑定中的Raises For Not Applicable Keys选项,应用程序再次工作,而不关闭绑定本身。这可能意味着在设置连接到XPC服务的沙箱之前引发了异常,因此使应用程序出现错误。



正确的修复方法将是苹果将XPC













基于serenn建议我使用下面的代码使我的应用程序按预期行为:

  let sb = NSStoryboard(name:Main,bundle:nil)! 

// ---

rootWindowController = sb.instantiateControllerWithIdentifier(MainWindowController)as? NSWindowController

// ---

rootWindowController?.showWindow(self)



在我的测试中,我发现 rootWindowController?.showWindow(self)更好地显示窗口而不是 makeKeyAndOrderFront ,因为否则segue没有得到正确连接(弹出,等)。这个方法适合我。


I'm using the NSSavePanel in OS X 10.10 in a sandboxed app to let the user choose the save location of a file (pretty standard), however the app crashes when i call:

NSSavePanel *panel = [NSSavePanel savePanel];

I get this in the debugger:

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

This is my code in full:

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

                    }]; 
                });
            });
        }

Is this a known bug or is it something in my code? If it's a known bug can I get round it.

  • EDIT: This is how I'm getting around it until Apple fix it (thank's to @serren for the fix):

First uncheck the Is Initial Controller in your primary window controller (your App won't automatically launch the main window now).

Then:

In the AppDelegate.h:

#import <Cocoa/Cocoa.h>

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


@end

Finally in AppDelegate.m implement applicationDidFinishLaunching: like so (remember to set your initial controller identifier, here mine is "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...
}

This process will mean that the NSApplication's mainWindow property will be set to the rootController.window automatically. So if you want to get your main window at any time you can still call [[NSApplication sharedApplication] mainWindow]; Also the AppDelegate and the NSApplication singleton both have a strong reference to this window which is important (otherwise the window will be released and the App will crash).

Hope this helps for the time being.

解决方案

Short Description:

This look like a bug somehow related to ArrayController and perhaps any other similar controller for that mater or whatever it inherits or the bindings system in IB. Here is a simple code which demonstrates the problem in detail: https://www.dropbox.com/s/atwoc2hweh5fjk6/Bug.zip?dl=0

Long Description:

It looks like that something weird is going on inside the SDK.

In the example that I have provided I have a standard application generated with a standard Xcode 6.1 template. The application is sandboxed. Inside the application delegate we simply test if the NSSavePanel will fire without any problems. The ViewController declares a property called "array" which is later bound to an NSArrayController (see inside Main.storyboard).

If you launch the application in this setup you will see that the NSSavePanel fails. However, if we simply turn off the NSArrayController binding, the call to NSSavePanel miraculously work.

Therefore, it is safe to assume that this is nothing but a bad bug hidden underneath the latest SDK, which apple needs to fix.

Feel free to add the sample to your bug report to Apple.

Woraround:

It looks like if you disable the "Raises For Not Applicable Keys" option inside the array controller binding you get the application to work again without turning off the binding itself. This probably means that an exception is raised before setting up the sandbox connecting to the XPC service therefore making the application misbehave.

The proper fix will be for apple to put the XPC connection initialization code somewhere where it is guarded from weird errors and exceptions therefore ensuring that it is always working.

UPDATE

Based on serenn suggestion I use the following code to make my application behave as expected:

    let sb = NSStoryboard(name: "Main", bundle: nil)!

    // ---

    rootWindowController = sb.instantiateControllerWithIdentifier("MainWindowController") as? NSWindowController

    // ---

    rootWindowController?.showWindow(self)

In my tests I find that rootWindowController?.showWindow(self) works better to show the window instead of makeKeyAndOrderFront because otherwise the segues don't get properly connected (popups, etc). This method works for me.

这篇关于NSSavePanel崩溃在沙盒应用程序OS X 10.10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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