Reputation: 464
I have a WKWebView subclass which is able to display web pages like Google. Unfortunately it doesn't display ePub files with valid file URLs in the local file system. No errors are returned.
Probably I need to do some kind of manipulation with an ePub file before it's eligible to be opened via WKWebView?
Here is what I'm doing:
[self.webView loadRequest:[NSURLRequest requestWithURL:fileURL]];
Doing the same with UIWebView I was able to open any of my ePub files. But I can't use UIWebView because it's deprecated and will be dropped.
Upvotes: 3
Views: 1449
Reputation: 1676
First, There is a deprecated library, FolioReaderKit that does a very nice work presenting different *.epub files. However it is not maintained, and is using UIWebView which will prevent from applications using it to upload to the AppStore.
Second, the only actual out of the box iOS SDK I found that gives you a full UI solution are skyepub and Adobe which are partially asking for payment.
But looking around the cod, examples and tutorials I learned a lot...
After evading a lot I come up to these following conclusions:
EPUB is basically a zip file that incorporate within a website, usually including some index.html file with some pictures, css and fonts. What is an EPUB.
To supply EPUB locally on iOS you will have to parse unzip it locally and serve the main file behind it (again we are talking bout the main use case of an html file). you can use different libraries such EPUBKit
You might need to allow access to the local files when parsing them, this might require allowing non-tls requests...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0">
<dict>
<key>NSAllowsArbitraryLoads</key> <true/>
<key>NSExceptionDomains</key> <dict>
<key>localhost</key> <dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key> <true/>
<key>NSExceptionMinimumTLSVersion</key> <string>TLSv1.2</string>
<key>NSExceptionRequiresForwardSecrecy</key> <true/>
<key>NSIncludesSubdomains</key> <true/>
<key>NSRequiresCertificateTransparency</key> <false/>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> <true/>
<key>NSThirdPartyExceptionMinimumTLSVersion</key <string>TLSv1.2</string>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <true/>
</dict>
</dict>
</dict>
</plist>
You might need to add custom css and js code (evaluate within the WKWebView you will use to load the html file into) to accommodate to the UI you desire to supply. A great example that helped me a lot is the Style.css and Bridge.js files and their usage in FolioReaderKit
Hopes it shed some light over EPUBs and iOS
Upvotes: 0
Reputation: 464
Solved. The right way:
[self.webView loadFileURL:URL.filePathURL allowingReadAccessToURL:URL.filePathURL];
Or:
NSString *htmlString = [NSString stringWithContentsOfFile:URL.filePathURL.path encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:htmlString baseURL:nil];
Upvotes: 1