MZDownloadManager Documentation

repository·master·Indexed 22 days ago

https://github.com/mzeeshanid/mzdownloadmanager

An iOS library for managing file downloads using URLSession. It supports concurrent downloads, background tasks, and download resumption. Compatible with Xcode 8+ and iOS 9+, it can be installed via CocoaPods or Swift Package Manager.

Tokens
697
Snippets
2
Records
5
Agent score
28%

What's inside MZDownloadManager

  1. Overview of MZDownloadManager

    master

    MZDownloadManager is a file download manager for iOS that leverages the URLSession API. It is designed to handle large files and supports background downloading, allowing downloads to continue even when the app is in the background.

    Key capabilities include:

    • Downloading multiple files concurrently.
    • Resuming interrupted downloads (requires server-side support).
    • Pausing and retrying downloads.
    • Background execution support.
  2. Download files to a custom path

    master

    You can specify a custom destination for downloaded files using the addDownloadTask(fileName:fileURL:destinationPath:) method.

    Handling Completion and Missing Directories

    When a download completes, the manager attempts to move the file to the specified destinationPath.

    1. If the destination folder exists: The file is moved to the destination, and the success delegate method is called.
    2. If the destination folder does NOT exist: The manager calls the downloadRequestDestinationDoestNotExists(downloadModel:index:location:) delegate method. This gives you an opportunity to handle the file (e.g., by creating the directory) before it fails.
    3. If the delegate is not implemented: The download will trigger the failure delegate method.

    Important: The downloadRequestDestinationDoestNotExists delegate method is called on the session's queue, not the main thread.

    // Example usage of custom path download
    manager.addDownloadTask(fileName: "example.zip", fileURL: "https://example.com/file.zip", destinationPath: "/custom/path/")
    
    // Delegate implementation for missing destination
    func downloadRequestDestinationDoestNotExists(downloadModel: MZDownloadModel, index: Int, location: NSURL) {
        // Handle the missing directory here
    }