如何在UIWebview中保存本地加载的HTML文件 [英] How to save a locally loaded HTML file in UIWebview
本文介绍了如何在UIWebview中保存本地加载的HTML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用UIWebView编写一个富文本编辑器。为此,我使用一个模板文件作为启动器。
I am writing a rich text editor using UIWebView. To do this, I used a template file for a starter.
然后当用户完成编辑但尚未发布时,我想将当前内容保存为备份html文件,以防应用程序损坏。
Then when user finishes editing but has not published yet, I would like to save the current content into a back-up html file in case app corrupts.
我如何做?
推荐答案
/ p>
Here you go... buddy
NSFileHandle *file;
NSMutableData *data;
const char *bytestring = "black dog";//In your case html string here
data = [NSMutableData dataWithBytes:bytestring length:strlen(bytestring)];
NSString *path = //Path to your html file
if ([filemgr fileExistsAtPath:path] == YES){
NSLog (@"File exists");
file = [NSFileHandle fileHandleForUpdatingAtPath:path];
if (file == nil)
NSLog(@"Failed to open file");
[file writeData: data];
[file closeFile];
}
else
NSLog (@"File not found");
完成下面的教程
这篇关于如何在UIWebview中保存本地加载的HTML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文