I have an encrypted word/excel/pdf file locally stored which I need to preview in my iPad app. I understand that QLPreviewController or UiDocumentInteractionController could be
After doing some digging, I found out that QLPreviewController
is using UIWebView
underneath, and calls the loadRequest:
to load the requested file.
Another way to accomplish what you desire is to make a private Category on UIWebView
,
and use method swizzling to override the loadRequest:
method, and call instead the loadData:MIMEType:textEncodingName:baseURL:
method.
Beware that:
1) In low-memory scenarios (i.e. large files) a black screen with "Error to load the document" appears, if that concerns you. (The unhacked QLPreviewController knows how to handle these scenarios very well and present the document).
2) I'm not sure Apple are going to approve this kind of hack, although no private APIs are used here.
code:
@implementation UIWebView (QLHack)
- (void)MyloadRequest:(NSURLRequest *)request
{
// Check somehow that it's the call of your QLPreviewController
// If not, just call the original method.
if (!insideQLPreviewController)
{
// Call original implementation
[self MyloadRequest:request];
}
else
{
// Load the real data you want
[self loadData:data MIMEType:mimeType textEncodingName:nil baseURL:someURL];
}
}
+ (void)load
{
method_exchangeImplementations(class_getInstanceMethod(self, @selector(loadRequest:)), class_getInstanceMethod(self, @selector(MyloadRequest:)));
}
@end