2011-07-27 36 views
7

我對理解新的Lion's Sandbox有些問題。NSSavePanel和Sandbox

我知道Lion包含一個名爲Powerbox的可信守護進程,其工作是代表沙盒應用程序呈現和控制打開/保存對話框。

Code Signing And Application Sandboxing Guide說:

Any time an application running inside a sandbox invokes an NSOpenPanel or NSSavePanel dialog, rather than showing the panels directly, AppKit automatically asks the Powerbox to present the dialog. From a developer perspective, there are no code changes required in terms of how these panels are used; this process is fully transparent.

After the user selects a set of files or directories, the Powerbox uses new functionality in the sandbox kernel module to expand the invoking application's sandbox to allow access to the selected files. By the time the application code queries the panel for the returned URLs or filenames, it already has permission to access those files, and can continue to use the files through almost any API it already uses.

確定。我沒有使用此代碼一些實際測試:

NSSavePanel *savePanel = [NSSavePanel savePanel]; 
savePanel.delegate = self; 

savePanel.directoryURL = ...; 
savePanel.nameFieldStringValue = ...; 

[savePanel beginSheetModalForWindow:self.window 
        completionHandler:^(NSInteger returnCode) { 
/* the completion handler */ 
}]; 

奇怪的是,NSOpenSavePanelDelegate方法的,是被稱爲前完成處理,沒有對文件系統訪問文件。

這是正確的嗎?

但如果是這樣,代表的方法如panel:validateURL:error:變得沒用!

你能幫我解釋一下應用程序和Powerbox之間的關係嗎?

+1

爲什麼你的'validateURL:'方法需要訪問文件系統?有問題的文件的URL被傳遞給委託方法,您還需要什麼? –

+0

我想分析一下,例如,如果指定的URL是可寫的,如果沒有,則返回'NO'。 – Dev

+0

無論如何,你可以向我確認'NSOpenSavePanelDelegate'方法不能訪問文件系統?只有完成處理程序可以訪問選定的文件? (在我看來,官方文檔是缺乏的。) – Dev

回答

8

聯繫Apple後,我可以確認Rob Keniger寫了什麼:NSOpenSavePanelDelegate方法無法訪問沙盒應用程序中的文件系統。

+0

你好,我已經打開了一個[技術支持事件(TSI)](https://developer.apple.com/support/technical/submit/)。 – Dev

+0

啊,我明白了。上一次我用他們的回答是如此無用以至於我以後從未使用過。謝謝!順便說一下,你知道是否有任何方法在沙盒應用程序中使用[NSSavePanel savePanel]與故事板?沒有辦法使它工作。 – SpaceDog

+0

@Dev你有沒有對你的TSI有任何有用的回覆?我們 - 我認爲其他人 - 也有同樣的問題。 – Sebastian