OS X webview获取实际的文件名字符串

时间:2015-11-12 18:16:47

标签: objective-c macos webview

由于以下链接,我已在网络视图中成功实施了NSURLDownload。在代码中,我必须指定一个文件名。我宁愿使用正在下载的文件的文件名。我如何获得该文件名?

How to download a file from the webview in os x and save it to a specific location

2 个答案:

答案 0 :(得分:0)

您可以从请求参数中解析它,或者将其与调用代码分开传递。

答案 1 :(得分:0)

您可以从download:decideDestinationWithSuggestedFilename:代表实施NSURLDownloadDelegate方法。

这样的事情:

// somewhere in your code
myWebView.downloadDelegate = self;

- (void)download:(NSURLDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename {


    NSString *destinationFilename = [[NSHomeDirectory() stringByAppendingPathComponent:@"Desktop"]
                           stringByAppendingPathComponent:filename];
    [download setDestination:destinationFilename allowOverwrite:YES];

}