在我们工程中,经常会有help文档,但是help文档一帮采用heml语言写的,然后用webview载入,那么编译日期,版本就需要自己手动改,十分繁琐,如何将日期,版本号,传入,就用到了一个十分简单的知识,而且效果也很好。
NSString* mainbundleDirectory = [[NSBundle mainBundle] bundlePath];
NSString* path = [mainbundleDirectory stringByAppendingPathComponent:htmlDoc];
NSString * htmlString = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSURL* url = [NSURL fileURLWithPath:path];
//NSURLRequest* request = [NSURLRequest requestWithURL:url];
myWebView.delegate = self;
myWebView.alpha = 0.0;
//获取编译的时间
NSDate * date = [NSDate date];
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"YYYY-MM-dd"];
NSString * dateStr = [formatter stringFromDate:date];
//获取版本号
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];
//获取程序名
NSString *appname = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleNameKey];
[self.myWebView loadHTMLString:[NSString stringWithFormat:htmlString,appname,version,dateStr] baseURL:url];
然后在需要引入参数的地方,在html里面用%@,或者%d表示,就ok拉,是不是很方便呢!
本文介绍了一种在iOS应用中自动更新HTML帮助文档的方法,通过在加载HTML文件时动态插入当前应用的版本号及编译日期,简化了维护文档的工作流程。
3万+

被折叠的 条评论
为什么被折叠?



