Latest 0.0.9
Homepage https://github.com/antonyharfield/FirebaseStorageCache
License MIT
Platforms ios 9.0
Dependencies Firebase/Core, Firebase/Storage
Frameworks FirebaseCore, FirebaseStorage
Authors

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.

Latest podspec

{
    "name": "FirebaseStorageCache",
    "version": "0.0.9",
    "summary": "FIRStorage for iOS with caching and offline capabilities.",
    "description": "Is your Firebase Storage code hitting the network too often? Would you like FirebasenStorage to cache images so that it works in offline mode? FirebaseStorageCache providesna disk-based cache that does exactly that. Extensions for UIImageView and UIWebViewnmakes loading files easy from a FIRStorageReference.",
    "homepage": "https://github.com/antonyharfield/FirebaseStorageCache",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Antony Harfield": "[email protected]"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/antonyharfield/FirebaseStorageCache.git",
        "tag": "0.0.9"
    },
    "source_files": "FirebaseStorageCache",
    "frameworks": [
        "FirebaseCore",
        "FirebaseStorage"
    ],
    "dependencies": {
        "Firebase/Core": [],
        "Firebase/Storage": []
    },
    "pod_target_xcconfig": {
        "FRAMEWORK_SEARCH_PATHS": "$(inherited) $(PODS_ROOT)/**"
    }
}

Pin It on Pinterest

Share This