문제

I have a WebView that I want to save as a WebArchive. I just want to save the HTML part and not the referenced images. When I do the following, it appears to be creating a WebArchive with the images embedded as well.

[[[[[sourceSignatureWebView mainFrame] dataSource] webArchive] data]
  writeToFile:@"MyWebarchive.webarchive" atomically:YES];

Besides the fact that I don't want to embed the images, Safari seems to have trouble displaying the file and is showing a lot of binary gibberish wrapped around the HTML part I want. I know I can use textutil to create the file, but if possible would like to do it all inside Cocoa.

Does anyone know if this is doable? Any ideas would be much appreciated. Thanks!

도움이 되었습니까?

해결책

How about something like this:

WebDataSource *dataSource = [[sourceSignatureWebView mainFrame] dataSource];

WebArchive *archive = [[WebArchive alloc]
                       initWithMainResource:[dataSource mainResource]
                       subresources:nil
                       subframeArchives:nil];

[[archive data] writeToURL…

Or are you actually after an HTML file rather than web archive?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top