我正在編寫一個OS X沙盒應用程序。它接收@ 3x和@ 2x圖像文件,並將它們轉換爲較低分辨率的圖像。我通過將文件拖入應用程序窗口或使用NSOpenPanel選擇目錄來獲取圖像URL。使用OS X沙箱編寫多個文件
一旦圖像被拖動或選擇的文件夾,我運行一個for循環和使用該方法
-(BOOL)writeImage:(NSImage*)image toFile:(NSString*)file withRepresentation:(NSString*)extension{
CGImageRef cgRef = [image CGImageForProposedRect:NULL
context:nil
hints:nil];
NSBitmapImageRep *newRep = [[NSBitmapImageRep alloc] initWithCGImage:cgRef];
[newRep setSize:[image size]];
NSData *pngData = [newRep representationUsingType:[self getRepresentationType:extension] properties:nil];
return [pngData writeToFile:[file stringByAppendingString:[NSString stringWithFormat:@".%@",extension]] atomically:YES];
這破壞了沙箱模型調整每個圖像。我讀過我應該使用NSSavePanel,但這需要我爲每個保存的圖像指定最終的文件路徑/文件名,這會破壞用戶體驗。
有什麼辦法可以讓沙盒應用程序permision寫入某個目錄,而不是要求寫入每個文件的權限?
向搜索引擎詢問有關安全範圍的書籤。 – 2014-12-03 01:09:32
也許你有這樣做的其他原因,但你可以使用automator做批量圖像調整大小... – Fonix 2014-12-03 01:46:01