I am trying to create a WebArchive from a WebView. I have it working, but I have found a problem when I try and work with edited content. This is what I am currently doing:
[webView setEditable:YES];
WebDataSource *dataSource = [[webView mainFrame] dataSource];
WebArchive *archive = [[WebArchive alloc]
initWithMainResource:[dataSource mainResource]
subresources:nil
subframeArchives:nil];
[[archive data] writeToFile:destinationPath atomically:YES];
[[webView mainFrame]
loadRequest:[NSURLRequest
requestWithURL:
[NSURL fileURLWithPath:destinationPath]
]];
Any edits I make to the content in the WebView do not get stored in the WebArchive. Do I need to commit my changes back to the original file in order for this to work? I would like it to save based on the content that is in the WebView. Any 开发者_JAVA百科help would be appreciated. Thanks!
After digging for awhile, I was able to figure out the answer to my own question. Here is how I did it:
WebResource *dataSource = [[[[webView mainFrame] DOMDocument] webArchive] mainResource];
WebArchive *archive = [[WebArchive alloc]
initWithMainResource:dataSource
subresources:nil
subframeArchives:nil];
[[archive data] writeToFile:@"output.webarchive" atomically:YES];
Hope that helps someone.
精彩评论