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 という名前のリスナーのエンドポイントを作成できない

権利は次のとおりです。

ここに画像の説明を入力

私もこれを試しましたが成功しませんでした。

4

1 に答える 1