CocoaPods trunk is moving to be read-only. Read more on the blog, there are 12 months to go.

FirebaseStorageCache 0.0.10

FirebaseStorageCache 0.0.10

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Mar 2018
SPMSupports SPM

Maintained by Antony Harfield, Thanakorn Amnuaywiboolpol.



 
Depends on:
Firebase/Core>= 0
Firebase/Storage>= 0
 

  • By
  • Antony Harfield

FirebaseStorageCache

FIRStorage for iOS with caching and offline capabilities

CI Status
Version
License
Platform

Demo

Clone/download FirebaseOfflineAppDemo and run pod install before pressing play in Xcode. The demo contains 3 examples: no caching, NSCache and FirebaseStorageCache.

Requirements

This project assumes that you have already setup Firebase for iOS.

Installation

FirebaseStorageCache is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'FirebaseStorageCache'

Usage

Use the default shared cache

let ref: FIRStorageReference = ...
FirebaseStorageCache.main.get(storageReference: ref) { data in
  // do something with your file
}

Create custom storage caches

let oneWeekDiskCache = DiskCache(name: "customCache", cacheDuration: 60 * 60 * 24 * 7)
let firStorageCache = FirebaseStorageCache(cache: oneWeekDiskCache)
firStorageCache.get(storageReference: ref) { data in
  // do something with your file
}

Extension for loading images (in UIImageView)

imageView.setImage(storageReference: ref)

Extension for loading web pages (in UIWebView and WKWebView)

Simple:

webView.loadHTML(storageReference: ref)

With post processing on the HTML:

let styleHTML: (Data) -> Data = { data in
            let pre = "<style>body {margin: 16px}</style>"
            var preData = pre.data(using: .utf8) ?? Data()
            preData.append(data)
            return preData
        }
webView.loadHTML(storageReference: ref, postProcess: styleHTML)

Cleaning/pruning the cache

In the didFinishLaunchingWithOptions of your AppDelegate, you should call the prune()
method of your disk caches to remove any old files:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        FIRApp.configure()
        FirebaseStorageCache.main.prune()
        return true
    }

Author

Antony Harfield, [email protected]

License

FirebaseStorageCache is available under the MIT license. See the LICENSE file for more info.