Cocoa app crashes when trying to open a save dialog: Timeout occured while waiting for the window

StackOverflow https://stackoverflow.com/questions/17777116

  •  03-06-2022
  •  | 
  •  

I wrote an HTML5 app and I'm making a wrapper for it in Cocoa for the Mac. I'm in the process of writing a method that will take a url and let the user save it to their disk. Here is the method so far:

- (void) downloadFile: (NSString *) url {

    NSSavePanel * savePanel = [NSSavePanel savePanel];
    [savePanel setAllowedFileTypes: @[@"png"]];
    [savePanel setNameFieldStringValue:@"test"];
    [savePanel beginWithCompletionHandler:^(NSInteger result){
        //NSArray * files = [[openDlg URLs] valueForKey: @"relativePath"];
        //[resultListener chooseFilenames: files]  ;
    }];
    [savePanel runModal];

}

However when I invoke the method (long after the window is made) my app crashes and I get this error in the console: 2013-07-21 18:23:05.067 Reditr[31458:d11f] RVS:__54-[NSRemoteSavePanel _runOrderingOperationWithContext:]_block_invoke_0319 : Timeout occured while waiting for the window

有帮助吗?

解决方案

You don't want to use both -runModal and -beginWithCompletionHandler:. Use one or the other (preferably the latter).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top