I would like to know if there are any alternatives to the loadData
(iOS 9 only) function of WKWebView
without using it's older brother UIWebView
.
Maybe there's a way to display document files (xlsx,docx,pptx,pdf,images) using the loadHTMLString
like how I display audio or video files in my code below.
It has to be able to accept NSData
because the file is encrypted at all times in the disk, so loadRequest
is not possible
Below is my code for viewing files:
if ( mimeType == kMimeTypeVideo || mimeType == kMimeTypeAudio ) {
NSString *contentType = [MIMETypeToFileExtViceVersaConverter convertFileExtensionToMimeType:shareWithObject.fileExtension];
NSString *base64String = [fileData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
NSString *str = [NSString stringWithFormat:@" \
<html><head></head><body style=\"margin:0;width:100%%;height:100%%;\">\
<video controls height=\"100%%\" width=\"100%%\"> \
<source type=\"%@\" src=\"data:%@;base64,%@\"> \
</video></body></html>", contentType, contentType, base64String];
[_webView loadHTMLString:str baseURL:[[NSBundle mainBundle] resourceURL]];
} else {
NSString *contentType = [MIMETypeToFileExtViceVersaConverter convertFileExtensionToMimeType:shareWithObject.fileExtension];
[_webView loadData:fileData MIMEType:contentType characterEncodingName:@"UTF-8" baseURL:[[NSBundle mainBundle] resourceURL]];
}