Classes
The following classes are available globally.
-
SDEDownloadManager
is a download management tool, support background download.If you want to build interface to display and manage download tasks, or track download activity,
DownloadListController
is a good choice, which is a UITableViewController subclass to coordinate withSDEDownloadManager
and has rich options to reduce a lot of work for you.Features:
- Basic download management: download/pause/stop/resume/restart/delete
All actions for the download task in
SDEDownloadManager
are basis on its download URL string.SDEDownloadManager
doesn’t support reduplicative task, but it doesn’t disable it totally: URL(string: URLString) and URL(string: URLString.uppercased()) request the same file.- As a data source for UITableView/UICollectionView
SDEDownloadManager
maintains a download list([[String]]
), so it could manage download task based on its location(IndexPath
) also.- Sort download list
Use
sortListBy(type:order:)
to change the order of download list. It supports to switch between five types:manual
,addTime
,fileName
,fileSize
andfileType
. I classify these sort types as two modes: manual mode and predefined mode(latter four types).You could choose its sort mode when create a download manager inmanager(identifier:manualMode:)
.Specially, in manual mode, a section in
downloadList
must has a title, and it will lose all section titles when switching from manual mode to predefined mode. And all tasks will be integrated into a single section with a placeholder title when switching from predefined mode to manual mode.In manual mode, reorder tasks by
moveTask(at:to:)
andmoveTasks(inSection:to)
.sortListBy(type:order:)
is limited by file meta info and just use four predefined sort types,sortListBy(order:taskTrait:traitAscending:taskAscending:)
free you to custom sort function.- Control download count
Adjust
maxDownloadCount
to control the maximum count of tasks which download at the same time. Don’t worry, it’s good as you think.- Track download activity: download progress and speed
Download activity info is provided in
downloadActivityHandler
, you could use the closure to update view. CallbeginTrackingDownloadActivity()
to track download activity, it executesdownloadActivityHandler
every second in the background until there is no more download or callstopTrackingDownloadActivity()
to stop it.- Data persistence
When you need, call
saveData()
.SDEDownloadManager
use property list serialization to save data, so when you add custom meta info for task byfetchMetaInfoHandler
, it must be property list object. It has enough load and save performance for usual scenes which has almost under 10000 records. You’d better test it in your scene. If load performance is not good in your scene, I suggest that you create download manager in advance to leave time to load data.- Cache thumbnails for files
Request thumbnail by
requestThumbnail(forTask:targetHeight:orLaterProvidedInHandler:)
. Generally, only image and video should have thumbnail, but there are some scenes where you want to associate a image with the file, e.g., an album art for the song, a poster for the movie. You can custom thumbnail for any file(except for image) bysetCustomThumbnail(_:forTask:cacheInMemoryOnly:)
.- Authentication
SDEDownloadManager
handle part authentication types for you: Basic, Digest, and server trust. For other authentication types, you could handle them bysessionDidReceiveChallengeHandler
andtaskDidReceiveChallengeHandler
.- Custom Other Behaviors in Session Delegate
SDEDownloadManager
useNSURLSessionDownloadTask
to download files, and session delegate is internal, I leave closure interfaces to custom behaviors in session delegate. See MARK: Closures to Custom Behaviors in Session Delegate.- Trash
Enable this feature by
isTrashOpened
. If true, task to delete will be moved to the trash first; if false, task is deleted directly.- Handle app force quit in downloading and you don’t have to do anything.
Declaration
Swift
@objcMembers open class SDEDownloadManager: NSObject
-
URLPickerController
is just a UITableViewController subclass which allows multiple selection and execute a closure with selected strings. If string is not a valid URL, it won’t be displayed in the list.Sometimes URL link is too long to display completedly in the cell, there are some options to improve it:
adjustsCellFontSizeToFitWidth
: The simplest way.isFileNamePriorThanURL
: Only file name is enough sometimes.shouldDisplayTinyURLAtCellTop
: File name loose its location info, fix it by a not very conspicuous way.
Declaration
Swift
@objcMembers open class URLPickerController: SDETableViewController
-
A UITableViewController subclass which could enter multiple selection mode by editButtonItem.
See moreDownloadListController
is its subclass.Declaration
Swift
open class SDETableViewController: UITableViewController
-
DownloadTrackerCell
is the default UITableViewCell used inDownloadListController
. Its style is.subtitle
.It adds three subviews:
- a UILabel to display download speed;
- a UIProgressView to display download progress;
- a UIButton to pause/resume download.
These three views are customizable in
DownloadListController
:allowsTrackingSpeed
: determine whether to display speed.allowsTrackingProgress
: determine whether to display download progress bar.cellAccessoryButtonStyle
: custom button appearance and action method.
For any type UITableViewCell in
DownloadListController
, theirimageView
andtextLabel
are customziable:cellImageViewStyle
: display an icon, or index, or none.isFileNamePriorThanURL
: display file name or its download URL.
Declaration
Swift
open class DownloadTrackerCell: UITableViewCell
-
DownloadListController
is a UITableViewController subclass and is born to coordinate withSDEDownloadManager
to manage download tasks and track download activity.It has rich custom options:
You can display the whole download list, or specified part by
displayContent
.All elements in the default cell
DownloadTrackerCell
are customizable.
Of course, they are predefined and limited. If default cell can’t satisfy your needs, you could use your custom UITableViewCell. More details in init method:
init(downloadManager:tableViewStyle:registerCellClasses:configureCell:)
.Adjust max download count by
adjustButtonItem
.Sort list by
sortButtonItem
.Custom task management features in cell swipe. All features are disabled by default. Relative properties:
allowsStop
,allowsDeletion
,allowsRedownload
,allowsRestoration
.Support multiple selection. Task management features in multiple selection mode(also edit mode) could be customed in
leftNavigationItemActions
. Multiple selection is disabled by default. Two way to activate it:- editButtonItem: enable
allowsEditingByEditButtonItem
to display editButtonItem at the right of navigationBar, or put editButtonItem on somewhere directly. - long press gesture: enable
allowsEditingByLongPress
.
- editButtonItem: enable
Offer management features for all tasks on the toolbar. Disabled by default and enable it by
allowsManagingAllTasksOnToolBar
. These features could be customed intoolBarActions
.Predefined UIBarButtonItem has two appearances: title or icon. Relative properties:
barButtonAppearanceStyle
,buttonIconFilled
.Provide custom headerView in
headerViewProvider
.Custom selection behavior by
didSelectCellHandler
anddidDeselectCellHandler
.
Declaration
Swift
@objcMembers open class DownloadListController: SDETableViewController, AccessoryButtonDelegate, UIPopoverPresentationControllerDelegate
-
A UIViewController subclass like UIAlertController to display a slider.
See moreDeclaration
Swift
public class SliderAlertController: UIViewController, UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning