1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > ios webView 打开 ppt pdf

ios webView 打开 ppt pdf

时间:2023-12-31 14:55:07

相关推荐

ios webView 打开 ppt pdf

项目中最近添加了新功能,从第三方app 分享文件过来,并展示出来

相关MIMEType如下

代码实现

NSLog(@"filpath------%@", filpath);NSData *Data = [NSData dataWithContentsOfFile:_filePath];NSString *type = [filpath componentsSeparatedByString:@"."].lastObject;if ([type isEqualToString:@"docx"]){[self.webView loadData:Data MIMEType:@"application/vnd.openxmlformats-officedocument.wordprocessingml.document" textEncodingName:@"UTF-8" baseURL:[NSURL fileURLWithPath:NSTemporaryDirectory()]];}else if ([type isEqualToString:@"doc"]){[self.webView loadData:Data MIMEType:@"application/msword" textEncodingName:@"UTF-8" baseURL:[NSURL fileURLWithPath:NSTemporaryDirectory()]];}else if([type isEqualToString:@"txt"]){[self.webView loadData:Data MIMEType:@"text/plain" textEncodingName:@"UTF-8" baseURL:[NSURL fileURLWithPath:NSTemporaryDirectory()]];}else if([type isEqualToString:@"PDF"] || [type isEqualToString:@"pdf"]){[self.webView loadData:Data MIMEType:@"application/pdf" textEncodingName:@"UTF-8" baseURL:[NSURL fileURLWithPath:NSTemporaryDirectory()]];}else if([type isEqualToString:@"PNG"] || [type isEqualToString:@"png"]){[self.webView loadData:Data MIMEType:@"image/png" textEncodingName:@"UTF-8" baseURL:[NSURL fileURLWithPath:NSTemporaryDirectory()]];}else if([type isEqualToString:@"ppt"]){[self.webView loadData:Data MIMEType:@"application/vnd.ms-powerpoint" textEncodingName:@"UTF-8" baseURL:[NSURL fileURLWithPath:NSTemporaryDirectory()]];}else if ([type isEqualToString:@"pptx"]){[self.webView loadData:Data MIMEType:@"application/vnd.openxmlformats-officedocument.presentationml.presentation" textEncodingName:@"UTF-8" baseURL:[NSURL fileURLWithPath:NSTemporaryDirectory()]];}else if ([type isEqualToString:@"xlsx"]){[self.webView loadData:Data MIMEType:@"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" textEncodingName:@"UTF-8" baseURL:[NSURL fileURLWithPath:NSTemporaryDirectory()]];}else if ([type isEqualToString:@"xls"]){[self.webView loadData:Data MIMEType:@"application/vnd.ms-excel" textEncodingName:@"UTF-8" baseURL:[NSURL fileURLWithPath:NSTemporaryDirectory()]];}else{}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。