繁体   English   中英

将NSImage保存到可可中沙箱应用程序的磁盘上-CRASH

[英]Saving a NSImage to disk on a sandbox app in cocoa - CRASH

我有要保存到沙箱应用程序上的磁盘的此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的侦听器创建终结点

这里是权利:

在此处输入图片说明

我也尝试过, 没有成功。

[NSSavePanel savePanel];

[NSSavePanel openPanel];

根本无法在情节提要应用程序上的OSX 10.10、10.10.1和10.10.2上运行。

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

在OSX上的故事板应用程序出现一堆问题之后,我不再使用它们。 我正在做“使用XIBS”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM