1

我有这个 NSImage 我想在沙盒应用程序上保存到磁盘。

我有这个代码:

- (void)exportPNGImage:(NSImage *)image withName:(NSString*)name
{

  NSArray *windows =[[NSApplication sharedApplication] windows];
  NSWindow *window = windows[0];

  // Build a new name for the file using the current name and
  // the filename extension associated with the specified UTI.
  CFStringRef newExtension = UTTypeCopyPreferredTagWithClass(kUTTypePNG,
                                                             kUTTagClassFilenameExtension);
  NSString* newName = [[name stringByDeletingPathExtension]
                       stringByAppendingPathExtension:(__bridge NSString*)newExtension];

  NSSavePanel *panel = [NSSavePanel savePanel];
  [panel setNameFieldStringValue:newName];
  [panel setAllowsOtherFileTypes:NO];
  [panel setAllowedFileTypes:@[(__bridge NSString*)newExtension]];

  [panel beginSheetModalForWindow:window completionHandler:^(NSInteger result){
    if (result == NSFileHandlingPanelOKButton)
    {
      NSURL *fileURL = [panel URL];

      // Write the contents in the new format.
      NSBitmapImageRep *imgRep = [[image representations] objectAtIndex: 0];
      NSData *data = [imgRep representationUsingType: NSPNGFileType properties: nil];
      [data writeToURL:fileURL atomically:YES];

    }
  }];

}

崩溃:尝试连接到侦听器“com.apple.view-bridge”时发生错误:连接中断 - +[NSXPCSharedListener connectionForListenerNamed:fromServiceNamed:] 中的断言失败,/SourceCache/ViewBridge/ViewBridge-99/NSXPCSharedListener.m:394 ] NSXPCSharedListener 无法为名为 com.apple.view-bridge 的侦听器创建端点

以下是权利:

enter image description here

我也试过这个但没有成功。

4

1 回答 1

1
[NSSavePanel savePanel];

[NSSavePanel openPanel];

根本不适用于故事板应用程序上的 OSX 10.10、10.10.1 和 10.10.2。

苹果给我的解决方案是“使用 Xibs”。

After having a long list of problems with storyboard apps on OSX, I don't use them anymore. "Use XIBS" is what I am doing.

于 2015-05-06T10:40:41.847 回答