簡體   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