### Configure and Start a Download Task Source: https://github.com/danie1s/tiercel/blob/master/README.md This example demonstrates how to configure a download session with custom settings and initiate a download task. It also shows how to handle progress, success, and failure callbacks on the main queue. ```swift import Tiercel var configuration = SessionConfiguration() configuration.allowsCellularAccess = true configuration.maxConcurrentTasksLimit = 3 let manager = SessionManager("downloads", configuration: configuration) let task = manager.download("https://example.com/video.mp4") task?.progress(onMainQueue: true) { task in print("progress:", task.progress.fractionCompleted) }.success { task in print("saved to:", task.filePath) }.failure { _ in print("download failed") } ``` -------------------------------- ### Control Individual Download Tasks by URL or Instance Source: https://github.com/danie1s/tiercel/blob/master/README.md Manage download tasks using either their URL or the task instance itself. This allows for starting, suspending, canceling, and removing downloads programmatically. ```swift let url = "https://example.com/video.mp4" manager.start(url) manager.suspend(url) manager.cancel(url) manager.remove(url, completely: false) if let task = task { manager.start(task) manager.suspend(task) manager.cancel(task) manager.remove(task, completely: false) } ``` -------------------------------- ### Install Tiercel with CocoaPods Source: https://github.com/danie1s/tiercel/blob/master/README.md Use this snippet to add Tiercel to your iOS project via CocoaPods. Ensure your platform is set to iOS 12.0 or higher and frameworks are used. ```ruby platform :ios, '12.0' use_frameworks! target 'YourTargetName' do pod 'Tiercel' end ``` -------------------------------- ### Perform Batch Downloads Source: https://github.com/danie1s/tiercel/blob/master/README.md Initiate multiple downloads simultaneously using a list of URLs. This is useful for downloading a collection of files, such as episodes or assets. ```swift let urls = [ "https://example.com/episode-1.mp4", "https://example.com/episode-2.mp4" ] let tasks = manager.multiDownload(urls) print(tasks.count) ``` -------------------------------- ### Handle Background URL Session Events Source: https://github.com/danie1s/tiercel/blob/master/README.md Wire the completion handler from AppDelegate to the matching SessionManager to support native background session callbacks. This allows downloads to resume after the app relaunches. ```swift let downloadManagers = [managerA, managerB] func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) { for manager in downloadManagers where manager.identifier == identifier { manager.completionHandler = completionHandler break } } ``` -------------------------------- ### Configure Session Network Policy Source: https://github.com/danie1s/tiercel/blob/master/README.md Tune network behavior for different products or environments using SessionConfiguration. Set limits on concurrent tasks and control cellular, constrained, and expensive network access. ```swift var configuration = SessionConfiguration() configuration.maxConcurrentTasksLimit = 3 configuration.allowsCellularAccess = true configuration.allowsConstrainedNetworkAccess = true configuration.allowsExpensiveNetworkAccess = true let manager = SessionManager("downloads", configuration: configuration) ``` -------------------------------- ### Validate Downloaded File Integrity Source: https://github.com/danie1s/tiercel/blob/master/README.md Validate downloaded files when integrity matters using the validateFile method. Specify the expected checksum code, type, and whether to perform the check on the main queue. ```swift task?.validateFile(code: "9e2a3650530b563da297c9246acaad5c", type: .md5, onMainQueue: true) { task in if task.validation == .correct { print("file is valid") } else { print("file is invalid") } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.