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 with SDEDownloadManager 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 and fileType. 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 in manager(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:) and moveTasks(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. Call beginTrackingDownloadActivity() to track download activity, it executes downloadActivityHandler every second in the background until there is no more download or call stopTrackingDownloadActivity() 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 by fetchMetaInfoHandler, 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) by setCustomThumbnail(_:forTask:cacheInMemoryOnly:).

    • Authentication

    SDEDownloadManager handle part authentication types for you: Basic, Digest, and server trust. For other authentication types, you could handle them by sessionDidReceiveChallengeHandler and taskDidReceiveChallengeHandler.

    • Custom Other Behaviors in Session Delegate

    SDEDownloadManager use NSURLSessionDownloadTask 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.
    See more

    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:

    1. adjustsCellFontSizeToFitWidth: The simplest way.
    2. isFileNamePriorThanURL: Only file name is enough sometimes.
    3. shouldDisplayTinyURLAtCellTop: File name loose its location info, fix it by a not very conspicuous way.
    See more

    Declaration

    Swift

    @objcMembers open class URLPickerController: SDETableViewController
  • DownloadTrackerCell is the default UITableViewCell used in DownloadListController. Its style is .subtitle.

    It adds three subviews:

    1. a UILabel to display download speed;
    2. a UIProgressView to display download progress;
    3. a UIButton to pause/resume download.

    These three views are customizable in DownloadListController:

    1. allowsTrackingSpeed: determine whether to display speed.
    2. allowsTrackingProgress: determine whether to display download progress bar.
    3. cellAccessoryButtonStyle: custom button appearance and action method.

    For any type UITableViewCell in DownloadListController, their imageView and textLabel are customziable:

    1. cellImageViewStyle: display an icon, or index, or none.
    2. isFileNamePriorThanURL: display file name or its download URL.
    See more

    Declaration

    Swift

    open class DownloadTrackerCell: UITableViewCell
  • DownloadListController is a UITableViewController subclass and is born to coordinate with SDEDownloadManager 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:

      1. editButtonItem: enable allowsEditingByEditButtonItem to display editButtonItem at the right of navigationBar, or put editButtonItem on somewhere directly.
      2. long press gesture: enable allowsEditingByLongPress.
    • Offer management features for all tasks on the toolbar. Disabled by default and enable it by allowsManagingAllTasksOnToolBar. These features could be customed in toolBarActions.

    • Predefined UIBarButtonItem has two appearances: title or icon. Relative properties: barButtonAppearanceStyle, buttonIconFilled.

    • Provide custom headerView in headerViewProvider.

    • Custom selection behavior by didSelectCellHandler and didDeselectCellHandler.

    See more

    Declaration

    Swift

    @objcMembers open class DownloadListController: SDETableViewController, AccessoryButtonDelegate, UIPopoverPresentationControllerDelegate
  • A UIViewController subclass like UIAlertController to display a slider.

    See more

    Declaration

    Swift

    public class SliderAlertController: UIViewController, UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning