2011-09-22 52 views
0

我正在使用NSSavePanel讓用戶選擇圖像保存到我的應用程序。一切工作正常,直到我啓用應用程序沙箱和權利。選擇已存在的文件時會出現問題。我的代碼是這樣的:NSSavePanel,CGImageDestinationFinalize和OS X沙箱

//創建一個URL到我們的文件目的地和一個CGImageDestination進行保存。 CGImageDestinationRef imageDestination = CGImageDestinationCreateWithURL((CFURLRef)[savePanel URL],(CFStringRef)newUTType,1,NULL); CGImageDestinationAddImage(imageDestination,cgimage,(CFDictionaryRef)metaData); const bool result = CGImageDestinationFinalize(imageDestination);

它選擇新文件保存圖像,但當我選擇現有的文件,它會創建除現有的文件之外的奇怪的命名文件,並無法覆蓋目標網址的內容。更糟糕的是,我沒有收到任何錯誤,也無法檢測到故障。這是CoreGraphics還是我的代碼中的錯誤?有沒有解決這個問題的方法?

+0

如果啓用應用程序沙箱和權利,我會得到與Apple提供的示例相同的結果MassiveImage http://developer.apple.com/library/mac/#samplecode/MassiveImage/Introduction/Intro.html)。我使用的唯一權利是com.apple.security.files.user-selected.read-write。此外,我知道,在沙盒應用程序(標準應用程序'預覽'是沙盒並覆蓋現有的圖像就好了)以某種方式覆蓋現有的文件是可能的。 –

回答

3

最後,我發現核心圖形調用的組合覆蓋了沙盒環境中已有的圖像:CGDataConsumerCreateWithURL,然後是CGImageDestinationCreateWithDataConsumer。所以看起來CGImageDestinationCreateWithURL已損壞(至少在OS X Lion 10.7.1)並啓用了沙箱。