我有这个 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 的侦听器创建端点
以下是权利:
我也试过这个但没有成功。