buzzfeed / mattress Goto Github PK
View Code? Open in Web Editor NEWiOS Offline Caching for Web Content
License: MIT License
iOS Offline Caching for Web Content
License: MIT License
I need to save multiple pages as user navigate through them, in example and in wiki you have used only 1 url should i use different database to store requested pages?
Is this project still alive?
Really need a Swift 4 version.
When including Mattress
via CocoaPods and manually specifying the SWIFT_VERSION
to 2.3, I get a compilation error with DiskCache.diskPath()
(line 457):
if !NSFileManager.defaultManager().fileExistsAtPath(fileURL.absoluteString, isDirectory: &isDir) {
...
}
The issue stems from the fact that NSFileManager.fileExistsAtPath(...)
accepts a non-optional string, so fileURL.absoluteString
has to be unwrapped.
I pushed a fix to my own fork and raised a PR - just not too sure if my solution is the most ideal given the rest of the context of DiskCache
. Let me know what you think ๐
When I add mattress to my project with alamofire and objectmapper this method in mattress says "stuff not nil"
func diskPathForRequest(request: NSURLRequest) -> NSURL? {
var url: NSURL?
if let
hash = hashForRequest(request),
baseURL = diskPath()
{
NSLog("stuff not nil")
url = NSURL(string: hash, relativeToURL: baseURL)
}
return url
}
Is there something I have to configure?
(null): error: /Users/kevinlord/Library/Developer/Xcode/DerivedData/Mattress-aqemttuzbkdmvefylygnstriakjp/Build/Products/Debug-iphoneos/CommonCrypto.framework: No such file or directory
(null): error: /Users/kevinlord/Library/Developer/Xcode/DerivedData/Mattress-aqemttuzbkdmvefylygnstriakjp/Build/Products/Debug-iphoneos/Mattress.framework: No such file or directory
Seems the project has a dependency to kevins mac ;)
Hi,
after installation via cocoa pods this line
let urlCache = Mattress.URLCache(memoryCapacity: 20 * MB, diskCapacity: 20 * MB, diskPath: nil,
mattressDiskCapacity: 1 * GB, mattressDiskPath: nil, mattressSearchPathDirectory: .DocumentDirectory,
isOfflineHandler: isOfflineHandler)
shows an error Use of unresolved identifier 'Mattress'
It shouldn't affect functionality, but the key used to store our current cache size is labeled as "maxCacheSize", which it is not. The maxCacheSize gets passed in on initialization each time. We should rename that, and while we're at it, go ahead and capitalize those DictionaryKey constants for style.
Hi,
could you please add Reachability as a dependency and/ or write this in the documentation? I added pod 'ReachabilitySwift', '~> 2.1' to my podfile and needed to update your example to the code below:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
setupCaching()
return true
}
private func setupCaching(){
do{
let reach = try Reachability.reachabilityForInternetConnection()
try reach.startNotifier()
let kB = 1024
let MB = 1024 * kB
let GB = 1024 * MB
let isOfflineHandler: (() -> Bool) = {
let isOffline = reach.currentReachabilityStatus == Reachability.NetworkStatus.NotReachable
return isOffline
}
let urlCache = Mattress.URLCache(memoryCapacity: 20 * MB, diskCapacity: 20 * MB, diskPath: nil,
mattressDiskCapacity: 1 * GB, mattressDiskPath: nil, mattressSearchPathDirectory: .DocumentDirectory,
isOfflineHandler: isOfflineHandler)
NSURLCache.setSharedURLCache(urlCache)
}
catch let err as NSError {
print("Error with caching: " + err.localizedDescription)
}
}
Hi I recognized that currently the data is stored outside the Mattress directory. Could you fix this please?
E.g. the data is currently stored here: "/Documents/00d550086fdea685f9832b96a29be3e0"
Mattress/Source/URLProtocol.swift:198:27: 'init(request:delegate:)' was deprecated in iOS 9.0: Use NSURLSession (see NSURLSession.h)
Could you remove this warning please?
I'm creating a conference app with an integration of some websites for venue, sponsors etc. This pages do not change quite often and it would be great to ship them cached with the app store build.
Some users start the app at the conference center for the first time where wifi conditions are sometimes very poor. Instead of showing a blank page the users should see at least "something".
It would be great if mattress could support this. What I currently would do is caching the websites within the simulator, cache the contents of the required pages and zip the mattress folder afterwards to ship it with the app (Currently there is a bug, see #33).
Is there something that can be solved by mattress to improve this process? For example that mattress could create the zip-file and present a mail dialog to bring the file to the devs machine? Or to update the cache automatically before creating the app store build?
Will the cache be working on other devices?
Hi - i currently have a big Objective C Project that will not be migrated to Swift. It has been migrated to iOS9 as minimum deployment target.
Now I imported Mattress via cocoapods and and added the use_frameworks! tag. This causes problems with other imported libraries.
Have you planned to implement support for Objective C that is compatible to other library?
Another point is that I get a warning regarding deprecation of NSURLConnection in your lib with iOS9.
I have recognized that a page often ends loading with a different state. I printing the line
let state = webView.stringByEvaluatingJavaScriptFromString("document.readyState")
to the console. Sometimes it finishes with "interactive" and sometimes with "completed" when loading the same url. Should the caching process then be repeated?
I tried to cache different pages consequently by calling.
cachePage(SiteA)
cachePage(SiteB)
cachePage(SiteC)
Is it possible that I have to wait until the former caching process has been completed? What I'm trying to achieve is that my apps caches certain pages after initialization to present them as fast as possible when the user visits them.
Another question: Does the caching mechanism needs an instance of a webView in my class or can it cache independently, so that I can put cachePage in it's own model class?
func cachePage(url: NSURL) {
log.info("Caching page \(url.absoluteString)")
if let cache = NSURLCache.sharedURLCache() as? Mattress.URLCache
{
cache.diskCacheURL(url, loadedHandler: { (webView) -> (Bool) in
let state = webView.stringByEvaluatingJavaScriptFromString("document.readyState")
log.verbose("state: \(state)")
return state == "complete"
}, completeHandler: { () -> Void in
log.info("Finished caching \(url.absoluteString)")
}, failureHandler: { (error) -> Void in
log.error("Error caching: \(error.localizedDescription)")
})
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.