NSOpenPanel异常***断言失败 - [NSRemoteView serviceViewSubservice]

时间:2014-03-10 12:38:38

标签: cocoa nsopenpanel

如果我试试这个:

NSOpenPanel * openPanel = [NSOpenPanel openPanel];
openPanel.canChooseDirectories    = YES;
openPanel.canChooseFiles          = YES;
openPanel.canCreateDirectories    = NO;
openPanel.allowsMultipleSelection = YES;
openPanel.title = @"Select files or folders to import";

[openPanel beginSheetModalForWindow: self.window
                  completionHandler: ^(NSInteger result) {
    if (result != NSFileHandlingPanelOKButton)
    {
        return;
    }
}];

它有时会起作用,但有时我会收到错误消息,例如:

*** Assertion failure in -[NSRemoteView serviceViewSubservice], /SourceCache/ViewBridge/ViewBridge-46.2/NSRemoteView.m:2679 2014-03-10 09:34:35.592 AppWage[52168:303] An uncaught exception was raised 2014-03-10 09:34:35.593 AppWage[52168:303] invalid 2014-03-10 09:34:35.593 AppWage[52168:303] ( 0 CoreFoundation 0x00007fff8a59825c __exceptionPreprocess + 172 1 libobjc.A.dylib 0x00007fff881fce75 objc_exception_throw + 43 2 CoreFoundation 0x00007fff8a598038 +[NSException raise:format:arguments:] + 104 3 Foundation 0x00007fff925ebd41 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189 4 ViewBridge 0x00007fff8736f8b0 -[NSRemoteView serviceViewSubservice] + 149 5 ViewBridge 0x00007fff873716d6 -[NSRemoteView viewServiceMarshalProxy:withErrorHandler:] + 43 6 ViewBridge 0x00007fff87366a40 -[NSRemoteView syncServiceWindow] + 32 7 ViewBridge 0x00007fff87367054 -[NSRemoteView didSetOriginOrSize:] + 201 8 ViewBridge 0x00007fff87367706 -[NSRemoteView setFrameSize:] + 231 9 AppKit 0x00007fff9042df3e -[NSWindow _oldPlaceWindow:] + 1644 10 AppKit 0x00007fff9042cf8c -[NSWindow _setFrameCommon:display:stashSize:] + 1633 11 ViewBridge 0x00007fff87373711 -[NSRemoteView serviceWindowDidResizeInProgress:] + 440 12 ViewBridge 0x00007fff873737d0 -[NSRemoteView serviceWindowDidResize:] + 180 13 ViewBridge 0x00007fff873707cf -[NSRemoteView advanceToConfigPhase] + 2458 14 ViewBridge 0x00007fff8737177c -[NSRemoteView viewServiceMarshalProxy:withErrorHandler:] + 209 15 ViewBridge 0x00007fff8736d9b7 -[NSRemoteView sendFontSmoothingBackgroundColorToService:] + 436 16 ViewBridge 0x00007fff8736e725 -[NSRemoteView viewDidMoveToWindow] + 197 17 AppKit 0x00007fff90323320 -[NSView _setWindow:] + 2899 18 AppKit 0x00007fff90320964 -[NSView addSubview:] + 364 19 AppKit 0x00007fff90334ac3 -[NSFrameView addSubview:] + 45 20 AppKit 0x00007fff90342df5 -[NSWindow setContentView:] + 511 21 AppKit 0x00007fff90ba9563 -[NSVBSavePanel init] + 287 22 AppKit 0x00007fff9092b389 +[NSSavePanel newRemotePanel] + 309 23 AppKit 0x00007fff9092b445 +[NSSavePanel _crunchyRawUnbonedPanel] + 120 24 AppWage 0x000000010006c99a -[AppDelegate onImportSalesReports:] + 714 25 AppKit 0x00007fff9052a340 -[NSApplication sendAction:to:from:] + 327 26 AppKit 0x00007fff905452a8 -[NSMenuItem _corePerformAction] + 394 27 AppKit 0x00007fff90544fe4 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 117 28 AppKit 0x00007fff9059448d -[NSMenu _internalPerformActionForItemAtIndex:] + 35 29 AppKit 0x00007fff90594309 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 104 30 AppKit 0x00007fff9053b0d6 NSSLMMenuEventHandler + 716 31 HIToolbox 0x00007fff8f5b91d4 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 892 32 HIToolbox 0x00007fff8f5b8787 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 385 33 HIToolbox 0x00007fff8f5cc880 SendEventToEventTarget + 40 34 HIToolbox 0x00007fff8f602640 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 420 35 HIToolbox 0x00007fff8f635238 SendMenuCommandWithContextAndModifiers + 59 36 HIToolbox 0x00007fff8f6351e0 SendMenuItemSelectedEvent + 178 37 HIToolbox 0x00007fff8f6350bf _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 94 38 HIToolbox 0x00007fff8f63d095 _ZL14MenuSelectCoreP8MenuData5PointdjPP13OpaqueMenuRefPt + 718 39 HIToolbox 0x00007fff8f63ccc1 _HandleMenuSelection2 + 446 40 AppKit 0x00007fff904ad73c _NSHandleCarbonMenuEvent + 284 41 AppKit 0x00007fff9030c6be _DPSNextEvent + 2170 42 AppKit 0x00007fff9030ba2b -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122 43 AppKit 0x00007fff902ffb2c -[NSApplication run] + 553 44 AppKit 0x00007fff902ea913 NSApplicationMain + 940 45 AppWage 0x000000010009a872 main + 34 46 libdyld.dylib 0x00007fff8cfb15fd start + 1 47 ??? 0x0000000000000003 0x0 + 3

如果我将打开的面板切换为:

[openPanel beginWithCompletionHandler: ^(NSInteger result) {
    if (result != NSFileHandlingPanelOKButton) {
        return;
    }
}];

它没有错误,但是打开的面板不再是我主窗口的工作表。

我没有使用正确的方式启动NSOpenPanel

4 个答案:

答案 0 :(得分:1)

重新启动系统后,此操作停止了。提出错误报告的Mac Developers forum建议已经完成。

答案 1 :(得分:1)

如果您处于沙盒环境中,请确保您具有访问文件的正确权利。

在权利文件中设置com.apple.security.files.user-selected.read-write = YES至少对我来说解决了这个问题。

答案 2 :(得分:0)

在我的情况下,这可以通过清理项目并再次构建来解决。可能与沙箱有关。

答案 3 :(得分:-1)

我可以通过在保存操作过程中创建一个新文件夹来获得相同的错误。

如果我不创建新文件夹,我不会收到错误。

错误不会因重新启动或清除而消失。

// this saves the view as a PDF
- (BOOL) saveViewAsPDF:(NSString *)myDrawingTitle toDirectory:(NSURL *)myDirectory {

    int runResult;
    BOOL OK = NO;

    // create or get the shared instance of NSSavePanel
    NSSavePanel * sp = [NSSavePanel savePanel];
    NSArray * fileTypes = @[@"pdf"];

    // set up new attributes
    [sp setAllowedFileTypes:fileTypes];

    [sp setNameFieldStringValue:myDrawingTitle];
    [sp setDirectoryURL:myDirectory];

    // display the NSSavePanel
    runResult = (int) [sp runModal];

// -- at this point in the cycle using the NSSavePanel to create a new folder --
// ... this error will result
//  *** Assertion failure in -[NSRemoteView updateWindowEdgeResizingRegion], /SourceCache/ViewBridge/ViewBridge-46.2/NSRemoteView.m:879

// the code then goes on and does the job (using the new folder even)

    MainController * myPtr2 = GetController();

    // if successful, save file under designated name
    if ( runResult == NSOKButton ) {    

        NSRect r = [super bounds];
        NSData * data = [self dataWithPDFInsideRect:r];
        NSURL * myURL = [sp URL];
        [data writeToURL:myURL atomically:YES];
        OK = YES;

        NSURL * myDirectory = [sp directoryURL];
        myPtr2->SetDefaultDirectoryForCurrentProcess( myDirectory );

    }

    return OK;
}