Created
February 23, 2015 08:53
-
-
Save nacho4d/e78554dcaa8ae6b2c4c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// There is a bug in WebKit | |
// Local files cannot be read unless they are in the tmp/www/ directory! | |
// Example: read "file.pdf" into WKWebView | |
var fileManager = NSFileManager.defaultManager() | |
var srcPath = NSBundle.mainBundle().pathForResource("file", ofType: "pdf") | |
var tmpPath = NSTemporaryDirectory().stringByAppendingPathComponent("www") | |
// TODO: handler errors correctly | |
fileManager.createDirectoryAtPath(tmpPath, withIntermediateDirectories: true, attributes: nil, error: nil) | |
var dstPath = tmpPath.stringByAppendingPathComponent("file.pdf") | |
if !fileManager.fileExistsAtPath(dstPath) { | |
// TODO: handle errors correctly | |
fileManager.copyItemAtPath(srcPath!, toPath: dstPath, error: nil) | |
} | |
// End of | |
let request = NSURLRequest(URL: NSURL.fileURLWithPath(dstPath)!) | |
self.webView.loadRequest(request) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment