I have this NSImage I want to save to disk on a sandbox app.
I have this code:
- (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];
}
}];
}
CRASH: an error occurred while attempting to connect to listener 'com.apple.view-bridge': Connection interrupted - Assertion failure in +[NSXPCSharedListener connectionForListenerNamed:fromServiceNamed:], /SourceCache/ViewBridge/ViewBridge-99/NSXPCSharedListener.m:394] NSXPCSharedListener unable to create endpoint for listener named com.apple.view-bridge
here are the entitlements:
I have also tried this without success.
[NSSavePanel savePanel];
and
[NSSavePanel openPanel];
simply don't work on OSX 10.10, 10.10.1 and 10.10.2 on storyboard apps.
The solution given by Apple to me was "use 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.