2011-01-14 70 views
0

我想從WebView創建一個WebArchive。我有它的工作,但是當我嘗試編輯內容時遇到了問題。這是我目前在做什麼:如何保存到WebArchive webView可編輯內容?

[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] 
    ]]; 

任何編輯我做在的WebView內容沒有得到存儲在WebArchive。我是否需要將我的更改恢復到原始文件才能正常工作?我希望根據WebView中的內容進行保存。任何幫助,將不勝感激。謝謝!

+0

這就是我正在做的,並在這裏工作確定(即writeToFile:原子:)。我想加載webarchive的內容返回到webview是有問題的。你能否檢查你在destinationPath中編寫的文件是否是你想要的,即編輯的文件? – 2011-01-14 07:25:05

回答

0

經過一段時間的挖掘,我能夠弄清楚我自己的問題的答案。以下是我如何做到的:

WebResource *dataSource = [[[[webView mainFrame] DOMDocument] webArchive] mainResource]; 

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

[[archive data] writeToFile:@"output.webarchive" atomically:YES]; 

希望能幫助別人。