{"id":15037809,"url":"https://github.com/sagarsdagdu/sddownloadmanager","last_synced_at":"2025-04-06T03:07:46.825Z","repository":{"id":62453462,"uuid":"99416194","full_name":"SagarSDagdu/SDDownloadManager","owner":"SagarSDagdu","description":"A simple, robust and elegant download manager supporting simultaneous downloads with closure syntax for progress and completion tracking. Written in Swift with ❤️ ","archived":false,"fork":false,"pushed_at":"2025-01-18T05:30:28.000Z","size":686,"stargazers_count":68,"open_issues_count":6,"forks_count":26,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-06T03:07:42.535Z","etag":null,"topics":["asynchronous-tasks","downloadmanager","ios","ios-swift","networking","swift-3","urlsession"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SagarSDagdu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-05T10:33:16.000Z","updated_at":"2025-04-04T11:34:51.000Z","dependencies_parsed_at":"2024-12-24T02:12:24.634Z","dependency_job_id":"ea50c34a-aaa0-4954-9e6c-1fd3907ed0dc","html_url":"https://github.com/SagarSDagdu/SDDownloadManager","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SagarSDagdu%2FSDDownloadManager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SagarSDagdu%2FSDDownloadManager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SagarSDagdu%2FSDDownloadManager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SagarSDagdu%2FSDDownloadManager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SagarSDagdu","download_url":"https://codeload.github.com/SagarSDagdu/SDDownloadManager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247427006,"owners_count":20937201,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asynchronous-tasks","downloadmanager","ios","ios-swift","networking","swift-3","urlsession"],"created_at":"2024-09-24T20:35:48.335Z","updated_at":"2025-04-06T03:07:46.798Z","avatar_url":"https://github.com/SagarSDagdu.png","language":"Swift","funding_links":["https://www.buymeacoffee.com/sagardagdu","https://img.buymeacoffee.com/button-api/?text=Buy"],"categories":[],"sub_categories":[],"readme":"SDDownloadManager\n=================\n![alt text](/SDDownloadManager/sddwn.png)\n\nA simple and robust download manager for iOS (Swift 5) based on `URLSession` to deal with asynchronous downloading and management of multiple files.\n\n`SDDownloadManager` is a singleton instance and can thus be called in your code safely from wherever you need to. The idea of writing yet another download manager library stemmed from the fact there are no available open source projects written using Swift based on the new `URLSession` APIs.\n\n***Background downloads are supported starting from version 1.1.0*** \n\n\n`SDDownloadManager` leverages the power of `URLSession` and `URLSessionDownloadTask` to make downloading of files and keeping track of their progress a breeze. Originally inspired by TWRDownloadManager (https://github.com/chasseurmic/TWRDownloadManager)\n\n- - - \n\n## Sponsorship\nI'm working on `SDDownloadManager` as a fun side project. I believe in the power of open source, and I'm thrilled to share it with you. If it saves you time and you’d like to show your appreciation, I would be incredibly grateful for your support.\n\n\u003ca href=\"https://www.buymeacoffee.com/sagardagdu\"\u003e\u003cimg src=\"https://img.buymeacoffee.com/button-api/?text=Buy me a coffee\u0026emoji=☕️\u0026slug=sagardagdu\u0026button_colour=FF5F5F\u0026font_colour=ffffff\u0026font_family=Arial\u0026outline_colour=000000\u0026coffee_colour=FFDD00\" /\u003e\u003c/a\u003e\n\n\n## Minimum iOS version support\n\niOS 12.0\n\n## Installing the library\n\nTo use the library, just add the dependency to your `Podfile`:\n\n```ruby\nplatform :ios\npod 'SDDownloadManager', '2.0.0'\n```\n\nRun `pod install` to install the dependencies.\n\n## Usage\n\n`SDDownloadManager` provides APIs for the following tasks:\n\n- Downloading multiple files asynchronusly to your specified directory.\n- Keeping track of download progress and download completion via closure syntax, no need to implement delegates!\n\n\n### Downloading files\n\n```swift\npublic func dowloadFile(withRequest request: URLRequest,\n                        inDirectory directory: String? = nil,\n                        withName fileName: String? = nil,\n                        onProgress progressBlock:DownloadProgressBlock? = nil,\n                        onCompletion completionBlock:@escaping DownloadCompletionBlock) -\u003e String? \n```\n\n#### Parameters :\n\n- `request` : A `URLRequest` which represents a downloadable resource.\n\n- `directory` : A `String` which represents a directory name inside the Caches directory of the app.\n\nAll the files, once downloaded will be moved from the `/tmp` directory of the device to the Caches directory. This is done for two reasons:\n \n  1) The `/tmp` directory can be cleaned once in a while to make sure that any partial, cancelled or failed downloads get properly disposed of and do not occupy space both on the device and in iTunes backups.\n  2) The Caches directory is not synced by default with the user's iCloud documents. This is in compliance with Apple's rules about content that – not being user-specific – can be re-downloaded from the internet and should not be synced with iCloud.\n\nIf a directory name is provided, a new sub-directory will be created in the Cached directory.\n\n- `fileName` : Once the file is finished downloading, if a `fileName` was provided by the user, it will be used to store the file in its final destination. If no name was provided the manager will use by default the suggested file name that comes in the response parameter OR last path component of the URL string (e.g. for `http://www.example.com/files/my_image.jpg`, the final file name would be `my_image.jpg`).\n\n- `progressBlock` : Called back with a `CGFloat` value ranging from 0 to 1.0 when the download progresses.\n\n- `completionBlock` : Called back with two parameters `error` and `fileUrl`.\n    - If the download was successful, `fileUrl` represents the URL of the file. The file can be accessed using this url.\n    - If the download was unsuccessful, `error` represents the error that occured in the downloading process.\n    \n#### Calling this method\n```swift\nSDDownloadManager.shared.downloadFile( /*Params */)\n```    \n    \n#### return\n\n- The method returns a key which is unique to that download call. Ideally, this key can be used later for cancelling the download or altering the progress block of a specific download.  ***If a download with the speicied urlrequest already exists, this method returns `nil`.***\n\n### Downloading files in background\n\nThe parameter `shouldDownloadInBackground` to the method `downloadFile()` decides whether the download should occur using a background session.\nFor background downloads to be supported, add this to your `AppDelegate`\n```swift\nfunc application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -\u003e Void) {\n    debugPrint(\"handleEventsForBackgroundURLSession: \\(identifier)\")\n    SDDownloadManager.shared.backgroundCompletionHandler = completionHandler\n}\n```\n\nIf you want to show a local notification after all background downloads finish, set `showLocalNotificationOnBackgroundDownloadDone` to `true`. You can set the text of local notification using `localNotificationText` property, Refer the following snippet : \n\n```swift\nSDDownloadManager.shared.showLocalNotificationOnBackgroundDownloadDone = true  // Set this if you want to issue a local notification when all the background downloads complete.\nSDDownloadManager.shared.localNotificationText = \"All background downloads complete\"  // Text for the local notification\nlet downloadKey = SDDownloadManager.shared.downloadFile(withRequest: request, inDirectory: directoryName, withName: directoryName, shouldDownloadInBackground: true, onProgress: { (progress) in\n        let percentage = String(format: \"%.1f %\", (progress * 100))\n        debugPrint(\"Background progress : \\(percentage)\")\n    }) { [weak self] (error, url) in\n        if let error = error {\n            print(\"Error is \\(error as NSError)\")\n        } else {\n            if let url = url {\n                print(\"Downloaded file's url is \\(url.path)\")\n            }\n        }\n    }\n```\n      \n### Checking for current downloads \n\nTo check if a file is being downloaded, you can use one of the following methods:\n```swift\npublic func isDownloadInProgress(forKey key:String?) -\u003e Bool\n```\n\nTo get all the dowloads that are in progress:\n```swift\npublic func currentDownloads() -\u003e [String]\n```\n\nTo alter the blocks of an ongoing download:\n```swift\npublic func alterDownload(withKey key:String?,\n                          onProgress progressBlock:DownloadProgressBlock?,\n                          onCompletion completionBlock:@escaping DownloadCompletionBlock)\n```\n### Cancelling downloads\n\nTo cancel all downloads:\n```swift\npublic func cancelAllDownloads()\n```\n\nTo cancel a specific download:\n\n```swift\npublic func cancelDownload(forUniqueKey key:String?)\n```\n                                  \n## Requirements\n\n`SDDownloadManager` requires iOS 12.x or greater.\n\n## Future Enhancements\n\nI'm planning to integrate the following features in upcoming releases :\n- ~~Background Downloads.~~ (Now supported starting from version 1.1.0)\n- Resumable Downloads.\n- A better and clean example project with more demonstration. (It will be great if I get some help in this from those who are actually using it!)\n\n## License\n\nUsage is provided under the [MIT License](http://opensource.org/licenses/mit-license.php).  See LICENSE for the full details.\n\n## Contributions\n\nAll contributions are welcome. Please fork the project to add functionalities and submit a pull request to merge them in next releases.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagarsdagdu%2Fsddownloadmanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsagarsdagdu%2Fsddownloadmanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagarsdagdu%2Fsddownloadmanager/lists"}