A drop-in framework for adding a background download manager to your iOS app.
CheapjackExample
project, as pictured above, demonstrates downloading multiple files and displaying their states in a custom UITableViewCell
.
For advanced usage and control over downloads refer to definitions in Cheapjack.swift.
Cheapjack's pretty simple to use.
class MyDownloadManager {
class func prepareForDownload() {
Cheapjack.downloadCompletionHandler = { (download, session, location) -> NSURL? in
// Return NSURL of location to move the file to once the download completes.
// Or do it manually and return nil.
return nil
}
}
func downloadFile() {
MyDownloadManager.prepareForDownload()
let url = NSURL("https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/HT1425/sample_iPod.m4v.zip") // 2.2 MB
Cheapjack.downloadWithURL(url, delegate: self)
}
}
In your app delegate implementation:
func application(application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: () -> Void) {
MyDownloadManager.prepareForDownload()
Cheapjack.backgroundSessionCompletionHandler = completionHandler
}
For download states and progress reporting, see Cheapjack.swift public methods and the full featured implementation in the included example project.
- iOS 8.1 SDK+
- Xcode 7+
Install with Carthage
Add the following to your Cartfile:
github "Gurpartap/Cheapjack"
Run carthage update --platform iOS
and follow the adding framework instructions in Carthage's README.
git clone https://github.com/Gurpartap/Cheapjack.git
cd Cheapjack
- Add Cheapjack.xcodeproj to your Xcode project or workspace.
- Add Cheapjack.framework to Linked Frameworks and Libraries in your app's target.
- Create a New Copy Files Phase with Frameworks as the Destination in the target's Build Phases.
- Add Cheapjack.framework to this Copy Files build phase.
- Try
import Cheapjack
in your code. Build should succeeed.