加载本地文件到UIWebView的方法

来源:互联网 发布:怎么找回手机淘宝密码 编辑:程序博客网 时间:2024/05/18 09:45

关键是生成“文件URL”

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);    NSString *documentsDirectory = [paths objectAtIndex:0];        NSString *path = [documentsDirectory stringByAppendingPathComponent:docName];        NSURL *url = [NSURL fileURLWithPath:path];    NSURLRequest *request = [NSURLRequest requestWithURL:url];     self.myWebView.scalesPageToFit = YES;     [self.myWebView loadRequest:request];

如果是资源文件,则用获取路径

NSString *mainBundleDirectory = [[NSBundle mainBundle] bundlePath];NSString *path = [mainBundleDirectory   stringByAppendingPathComponent:docName];




原创粉丝点击