Swift 工具库 Transporter

码农软件 · 软件分类 · 其他开发相关 · 2019-10-21 09:12:36

软件介绍

Transporter 是一个方便上传和下载的库。

特性

  • 支持并发或者顺序上传或者下载多个文件

  • 支持后台上传和下载

  • 支持进程跟踪 (单个任务或者任务组)

  • 支持重置,停止,取消,重试任务

  • header 可配置

  • 请求参数可配置

快速示例

let path = NSBundle.mainBundle().pathForResource("bigfile", ofType: "zip")let fileUrl = NSURL(fileURLWithPath: path!)!let task = UploadTask(url: "http://server.com", file: fileUrl)    .progress { sent, total in
        let per = Double(sent) / Double(total)
        println("uploading: \(per)")
    }    .completed { response, json, error in
        println("completed")
    }


 Transporter.add(task1 <--> task2 <--> task3)                     // concurrent tasks
            .progress { bytes, total in
                let per = Double(bytes) / Double(total)
                println("concurrent tasks: \(per)")
            }            .completed { alltasks in
                println("task1, task2, task3: completed")
            }            .add(task4 --> task5 --> task6)                       // serial tasks 
            .progress { bytes, total in
                println("serial tasks")
            }            .resume()

用法

// downloading tasklet task = DownloadTask(url: downloadUrl, destination: des)    .progress { bytes, total in
        let per = Double(bytes) / Double(total)
        println("downloading: \(per)")
    }    .completed { response, _, error in
        println("completed")
    }// uploading task// upload types: File, Data, Streamlet task = UploadTask(url: "http://server.com", data: uploadData)    .progress { sent, total in
        let per = Double(sent) / Double(total)
        println("uploading: \(per)")
    }    .completed { response, json, error in
        println("completed")
    }// tasktask.headers = ["key": "value"]
task.params = ["key": "value"]
task.pause()
task.cancel()
task.retry// background handling// add the following method in the app delegatefunc application(application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: () -> Void) {
    Transporter.handleEventsForBackgroundURLSection(identifier, completionHandler: completionHandler)
}// Transporter configurationsTransporter.headers = [key: value]
Transporter.timeoutIntervalForRequest = 30.0Transporter.timeoutIntervalForResource = 24 * 60 * 60.0Transporter.HTTPMaximumconnectionsPerHost = 5

本文地址:https://codercto.com/soft/d/17225.html

疯狂的独角兽

疯狂的独角兽

丹·莱昂斯 / 王天任 / 海南出版社 / 2017-10 / 42

★商业与文学的有机结合,真实与虚幻间嬉笑怒骂,幽默风趣、引人入胜、发人深省的商业小说。 ★《纽约时报》《华尔街日报》《旧金山纪事报》Amazon畅销书,《财富》《纽约邮报》《新闻周刊》《华盛顿邮报》、畅销书《硅谷钢铁侠》作者阿什利·万斯、畅销书《一网打尽》作者布拉德·斯通联袂推荐。 ★作者丹·莱昂斯集小说家、记者、编剧为一身——HBO经典热门剧、豆瓣高分美剧《硅谷》作者;畅销书《乔布斯......一起来看看 《疯狂的独角兽》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具