Docx support in UIWebview(iOS)?

后端 未结 3 2079
离开以前
离开以前 2021-02-06 06:44

I have checked the official links for doc support, and it\'s clear that docx is not supported in UIWebview.

But, I also found out that some guys were able to open docx f

3条回答
  •  生来不讨喜
    2021-02-06 07:44

    Don't know why but using the URL scheme to load docx didn't work, (below code didn't work)

     NSURLRequest *request = [NSURLRequest requestWithURL:urlPath];
    [webViewForDocsView loadRequest:request];
    

    Instead, loading the file in memory(using NSData) and loading the data with MIME type worked (the below code worked like charm!)

    NSString *path = [urlFileInView path];
    NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
    
    
    webViewForDocsView.delegate = self;
    [webViewForDocsView loadData:data MIMEType:@"application/vnd.openxmlformats-officedocument.wordprocessingml.document" textEncodingName:@"UTF-8" baseURL:nil];
    

提交回复
热议问题