WebView加载本地文件

            NSData *data = [NSData dataWithContentsOfFile:self.targetFileUrl];
            //获取文件类型
            NSURL *url = [NSURL fileURLWithPath:self.targetFileUrl];
            NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
            NSHTTPURLResponse *response = nil;
            [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
            [self.webView loadData:data MIMEType:response.MIMEType textEncodingName:@"UTF-8" baseURL:[NSURL fileURLWithPath:self.targetFileUrl]];

你可能感兴趣的:(WebView加载本地文件)