diff --git a/EVURLCache.podspec b/EVURLCache.podspec index 21dfbc8..9de4b79 100755 --- a/EVURLCache.podspec +++ b/EVURLCache.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| # s.name = "EVURLCache" -s.version = "3.3.1" +s.version = "3.5.0" s.summary = "NSURLCache subclass for handeling all web requests that use NSURLRequest" s.description = "This is a NSURLCache subclass for handeling all web requests that use NSURLRequest. (This includes UIWebView)" s.homepage = "https://github.com/evermeer/EVURLCache" diff --git a/EVURLCache.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/EVURLCache.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/EVURLCache.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/EVURLCache/Pod/EVURLCache.swift b/EVURLCache/Pod/EVURLCache.swift index 7334a58..615c987 100755 --- a/EVURLCache/Pod/EVURLCache.swift +++ b/EVURLCache/Pod/EVURLCache.swift @@ -168,11 +168,31 @@ open class EVURLCache: URLCache { // This works for the game, but not for my site. return response } else { - EVURLCache.debugLog("The file is probably not put in the local path using NSKeyedArchiver \(storagePath)") + // File was not written using the NSKeyedUnarchiver. Will return the raw file as the cache response + if let content:NSData = NSData(contentsOfFile: storagePath) { + let mimeType = getMimeType(storagePath) + let response = URLResponse(url: url, mimeType: mimeType, expectedContentLength: content.length, textEncodingName: nil) + EVURLCache.debugLog("CACHE returning cache response: mimeType = \(mimeType), path = \(storagePath)"); + return CachedURLResponse(response: response, data: content as Data) + } + EVURLCache.debugLog("CACHE could not be read from \(storagePath)") } return nil } + // Make sure the correct mimetype is returned from the cache + private static func getMimeType(_ path: String) -> String { + var mimeType = "text/html" + if let fileExtension: String = path.components(separatedBy: ".").last { + if let uti: CFString = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension as NSString, nil)?.takeRetainedValue() { + if let type = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() { + mimeType = type as String + } + } + } + return mimeType + } + // Will be called by NSURLConnection when a request is complete. open override func storeCachedResponse(_ cachedResponse: CachedURLResponse, for request: URLRequest) {