Cocoa webkit:如何在webkit中获取文件上载/文件系统访问权限

Fri*_*ard 0 cocoa webkit file-upload

我从WebKit框架创建了一个自定义浏览器.我几乎完成了所有设置.

但是,当访问带有文件上传的网页(比如flickr)时,按下"上传"按钮时没有任何反应.通常这会在safari/firefox /中弹出一个弹出窗口.

在Cocoa中使用WebKit进行文件上传需要什么?NSFileHandler,NSFileManager?我该怎么办?

此致,Friesgaard

Fri*_*ard 5

好吧,我认为我是出于自我.

在类中实现以下方法.将类设置UIDelegateWebViewInterface Builder中的类.

(如何使用NSOpenPanel我在这里找到的:http: //ekle.us/index.php/2006/12/displaying_a_file_open_dialog_in_cocoa_w )

- (void)webView:(WebView *)sender runOpenPanelForFileButtonWithResultListener:(id < WebOpenPanelResultListener >)resultListener
{       
    // Create the File Open Dialog class.
    NSOpenPanel* openDlg = [NSOpenPanel openPanel];

    // Enable the selection of files in the dialog.
    [openDlg setCanChooseFiles:YES];

    // Enable the selection of directories in the dialog.
    [openDlg setCanChooseDirectories:NO];

    // Display the dialog.  If the OK button was pressed,
    // process the files.
    if ( [openDlg runModalForDirectory:nil file:nil] == NSOKButton )
    {
        // Get an array containing the full filenames of all
        // files and directories selected.
        NSArray* files = [openDlg filenames];

        // Loop through all the files and process them.
        //for(int i = 0; i < [files count]; i++ )
        {
            NSString* fileName = [files objectAtIndex:0]; //i]; 
            // Do something with the filename.
            [resultListener chooseFilename:fileName]; 
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

PS.使用[resultListener chooseFilenames:...]多个文件