File downloading library for Swift 3

Overview

VeloxDownloader

About:

VeloxDownloader is an easy to use,elegant, native yet powerfull download library made with Swift 3. It abstracts all the complex implementations of urlsession and download tasks and provide a "one-click" API which enables you to download the files from the internet.

It's asyncronous, fast, maintainable, highly customizable, has backgrounding capabilities and provides In-built GUI to show and control the download progress of your files.

See it in Action: πŸ“Ή

VeloxDownloader Demo

What can it do? πŸ’ͺ🏼

  • It has following modes:
    • With UI:

      • As seen from above demo VeloxDownloader comes with an in built downloaing View that shows the download progress and currently has the ability to stop any download.
      • This API let you control if you want to enable background downloading for any specific file download.
    • WIthout UI:

      • This API uses Swift closures to return the download progress, time remaining and the completion status of your download. You can use this information to cater your needs or even build your own downloaing progress GUI.
      • This API also let you enable or disable the background downloading for any specific file download.

Usage: πŸ’»

  • Installation :

    VeloxDownloader can be installed using CocoaPods. Simply put the following line in your PodFile and run pod update from your terminal.

pod 'VeloxDownloader', '~> 1.6'

  • Importing:

    Once the pod successfully installs, open the xcode workspace project. In your viewcontroller simply import the VeloxDownloader by using following file.

    import VeloxDownloader

  • Apple's App Transport Security Settings (For http download links):

    If download links are in http, Make sure you have allowed Allowed Arbitary load in your info.plist for the App Transport Security Settings.

    screen shot 2016-12-04 at 5 36 39 pm

  • Using VeloxDownloader with Velox downloading UI:

    • I recommened using a scroll view to show the downloading files using the VeloxDownloading table view. Just set the VeloxDownloader view to your scroll view like following:
    override func viewDidLoad() {
         
         super.viewDidLoad()
         let bundle  = Bundle(for: VeloxDownloaderList.self)
         let controller = VeloxDownloaderList(nibName: "VeloxDownloaderList", bundle: bundle)
         self.addChildViewController(controller)
         
         // scrollView is the outlet variable for your scroll view.
         // it will be used to display velox downloading UI.
         controller.view.frame = scrollView.frame
         self.view.addSubview(controller.view)
         controller.didMove(toParentViewController: self)
         
     }
    

 * Next : Simply use the ```downloadFileWithVeloxDownloader``` like following. All you have to pass is the URL of the file you want to download and rest will be taken care of by the VeloxDownloader.

IBAction func downloadClicked(_ sender: Any) { let veloxDownloader = VeloxDownloadManager.sharedInstance

    let urlString = "URL OF YOUR FILE"
    let url = URL(string: urlString)

    veloxDownloader.downloadFileWithVeloxDownloader(
    withURL: url!, 
    name: url!.lastPathComponent,
    directoryName: nil, 
    friendlyName: nil, 
    backgroundingMode: false)        
}
 
* With BackGrounding: Simply pass true in the  ```backgroundingMode``` parameter of the above method.

veloxDownloader.downloadFileWithVeloxDownloader( withURL: url!, name: url!.lastPathComponent, directoryName: nil, friendlyName: nil, backgroundingMode: true)

   
* __Using VeloxDownloader without Velox downloading UI__:
 * If you are interested in building your own UI to show and track the progress of your downloads, than you can use the following closure syntax to do just that. Obvisiouly, with this mode you don't have to worry about setting the VeloxDownloader UI as we did above in viewDidLoad() method.

@IBAction func downloadClicked(_ sender: Any) { let veloxDownloader = VeloxDownloadManager.sharedInstance

    let urlString = "URL OF YOUR FILE"
    let url = URL(string: urlString)

    let progressClosure : (CGFloat,VeloxDownloadInstance) -> (Void)
    let remainingTimeClosure : (CGFloat) -> Void
    let completionClosure : (Bool) -> Void

    
    progressClosure = {(progress,downloadInstace) in           
    print("Progress of File : \(downloadInstace.filename) is \(Float(progress))")        
    }
       
    remainingTimeClosure = {(timeRemaning) in          
        print("Remaining Time is : \(timeRemaning)")
    }
    
    completionClosure = {(status) in
        print("is Download completed : \(status)")
    }
    
    
    veloxDownloader.downloadFile(
    withURL: url!, 
    name: url!.lastPathComponent, 
    directoryName: nil, 
    friendlyName: nil, 
    progressClosure: progressClosure, 
    remainigtTimeClosure: remainingTimeClosure, 
    completionClosure: completionClosure, 
    backgroundingMode: false)       
}
* With BackGrounding: Simply pass true in the  ```backgroundingMode``` parameter of the above method.

# How can I retrieve the downloaded files: πŸ—‚
* All the downloaded files are first downloaded in the temporary directory and post completion they are moved to the default cache directory of your application. 
* You have to manually retrieve the files from your cache diretory before the application is closed. You can use following code to scan you application cache directory:

  do{
     let cachesDirectoryURLPath = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0])
                    
     let dir = try FileManager.default.contentsOfDirectory(atPath: cachesDirectoryURLPath.path)
     for file in dir{
     print("file is : \(file)")
      }
     }
     catch let error as NSError{
     print("error occured while trying to read cache dir \(error.localizedDescription)")
     }

* VeloxDownloader clears out the temporary directory on every launch to avoid any file naming conflict and preseve system space.
* Also, if there is already a file present in the cache directory, VeloxDownloader removes the files and replaces the file.
* If download is stopped in the middle for a file than VeloxDownloader removes the file traces from the temp and cache directory.

# Demo: πŸ‘πŸΌ
Simply clone (or download) this git project and run it using Xcode 8 preferebally on an iOS 10 simulator or device:

```git clone https://github.com/nitinsh99/VeloxDownloader.git```


# Contribution: ❀️
* Please STAR the project or mention your project name in this [issue](https://github.com/nitinsh99/VeloxDownloader/issues/15) if you are feeling lucky.
* Create a seperate issue if you found a bug for if you have a feature request.
* You are welcome to submit a pull reqeust if you fixed a bug.

# What's cooking: 🍲
* I will be working on VeloxDowloading UI to add more features like play, pause, resume.
* I will be working on improving the VeloxDownloading UI to make it more asthetic.
* I will be working on improving the file management classes to give more flexibility on saving the downloaded files preferably by tying it up wiht SQLLite and/or CoreDate
* I will be working on creating a UI extenstion for file management that will make it easier to navigate and control through the list of downloaded files.
* More work on general notifications while the backgrounding is enabled.

# Credits: πŸ™πŸΌ
* Thanks to awesome people behind [Cocoapods](https://cocoapods.org/about)
* I took insipration from [this](https://github.com/chasseurmic/TWRDownloadManager) downloading library written for Obj-C to make VeloxDownloader.


# [License](https://github.com/nitinsh99/VeloxDownloader/blob/master/LICENSE)

You might also like...
Lightweight REST and JSON library for Swift.

RestEssentials is an extremely lightweight REST and JSON library for Swift and can be used on iOS, iPadOS, macOS, tvOS, and watchOS. Features Easily p

WebSocket(RFC-6455) library written using Swift

DNWebSocket Object-Oriented, Swift-style WebSocket Library (RFC 6455) for Swift-compatible Platforms. Tests Installation Requirements Usage Tests Conf

RSNetworking is a networking library written entirly for the Swift programming language.

RSNetworking is a networking library written entirly for the Swift programming language.

An awesome Swift HTML DSL library using result builders.

SwiftHtml An awesome Swift HTML DSL library using result builders. let doc = Document(.html5) { Html { Head { Meta()

Plugin and runtime library for using protobuf with Swift

Swift Protobuf Welcome to Swift Protobuf! Apple's Swift programming language is a perfect complement to Google's Protocol Buffer ("protobuf") serializ

Swift library for working with LSP

LanguageServerProtocol This is a Swift library for interacting with Language Server Protocol. It contains type definitions and utilities useful for bo

ServiceData is an HTTP networking library written in Swift which can download different types of data.

ServiceData Package Description : ServiceData is an HTTP networking library written in Swift which can download different types of data. Features List

A networking library for Swift
A networking library for Swift

Nikka Nikka is a super simple Swift HTTP networking library that comes with many extensions to make it modular and really powerful. Installation Usage

An unofficial supported Swift client library for accessing News API.

An unofficial supported Swift client library for accessing News API.

Comments
  • Issue related to re-downloading if file is already present in the cache

    Issue related to re-downloading if file is already present in the cache

    Also, if there is already a file present in the cache directory, VeloxDownloader removes the files and replaces the file.
    

    when i download my file the second time(mean i finished the first file,and press the download button second time):

    file1 got deleted : true
    file is finished downloading
    

    is this mean the second i download the file,it do not redownload the file from the remote url? instead it just replace the file?

    then i reopen the app,the temp file deleted,and the cache file still exist,i press the download btn ,the file download from remote url and replace the file that in the cache file?

    is that right above?

    bug 
    opened by bulolo 1
  • Problem with dowloadInstace

    Problem with dowloadInstace

    I Have Problem With Download Instance.I Use Swift For And I Import The Lib with CocoaPods but The xib file Wasn't imported so i changed your code a little bit.in VeloxDownloadList.Swift File I Change The @IBOutlet Connection to let downloadListTableView = UITableView() and Now I'm Getting Error With downloadInstance And IT says It is Empty.Also I Should Mention That I Don't want to use XIB Files. screen shot 2018-06-07 at 2 08 13 pm

    opened by alipishvaee 0
  • Projects using VeloxDownloader

    Projects using VeloxDownloader

    It helps me keep working on such projects knowing that other developers are finding it useful. Please take a moment to let me know you are using VeloxDownloader. Thanks!

    opened by nitinsh99 1
Releases(1.6)
Owner
Nitin Sharma
Professional Full Stack Software Programmer currently working on the JavaScript based stack at Walmart Labs.
Nitin Sharma
A modern download manager based on NSURLSession to deal with asynchronous downloading, management and persistence of multiple files.

TWRDownloadManager TWRDownloadManager A modern download manager for iOS (Objective C) based on NSURLSession to deal with asynchronous downloading, man

Michelangelo Chasseur 407 Nov 19, 2022
Digger is a lightweight download framework that requires only one line of code to complete the file download task

δΈ­ζ–‡θ―΄ζ˜Ž Digger is a lightweight download framework that requires only one line of code to complete the file download task. Based on URLSession, pure Swif

Ant 543 Oct 29, 2022
SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN.

SwiftCANLib SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN. Th

Tim Wise 4 Oct 25, 2021
Easy to use OAuth 2 library for iOS, written in Swift.

Heimdallr Heimdallr is an OAuth 2.0 client specifically designed for easy usage. It currently supports the resource owner password credentials grant f

trivago N.V. 628 Oct 17, 2022
Swift based OAuth library for iOS

OAuthSwift Swift based OAuth library for iOS and macOS. Support OAuth1.0, OAuth2.0 Twitter, Flickr, Github, Instagram, Foursquare, Fitbit, Withings, L

OAuthSwift 3.1k Jan 6, 2023
πŸ‡ A Swift HTTP / HTTPS networking library just incidentally execute on machines

Thus, programs must be written for people to read, and only incidentally for machines to execute. Harold Abelson, "Structure and Interpretation of Com

John Lui 845 Oct 30, 2022
Lightweight library for web server applications in Swift on macOS and Linux powered by coroutines.

Why Zewo? β€’ Support β€’ Community β€’ Contributing Zewo Zewo is a lightweight library for web applications in Swift. What sets Zewo apart? Zewo is not a w

Zewo 1.9k Dec 22, 2022
A lightweight library for writing HTTP web servers with Swift

Taylor Disclaimer: Not actively working on it anymore. You can check out some alternatives Swift 2.0 required. Working with Xcode 7.1. Disclaimer: It

Jorge Izquierdo 925 Nov 17, 2022
Super lightweight async HTTP server library in pure Swift runs in iOS / MacOS / Linux

Embassy Super lightweight async HTTP server in pure Swift. Please read: Embedded web server for iOS UI testing. See also: Our lightweight web framewor

Envoy 540 Dec 15, 2022
An Generic HTTP Request Library For Swift

GRequest An HTTP request library written in Swift. ##Basic Usage Be simple, as it should be: Request("https://api.github.com/repos/lingoer/SwiftyJSON/

Ruoyu Fu 114 Oct 18, 2022