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.
- If the destination folder exists: The file is moved to the destination, and the success delegate method is called.
- 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. - 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
}