Dropbox API 使用SwiftyDropbox库下载包含进度信息的文件
示例
根据本教程改编而成,它使用SwiftyDropbox库下载文件,并使用download方法上的进度回调来获取进度信息:
//下载档案
let destination : (NSURL, NSHTTPURLResponse) -> NSURL = { temporaryURL, response in
let fileManager = NSFileManager.defaultManager()
let directoryURL = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
//为这个文件生成一个唯一的名称,以防我们之前见过它
let UUID = NSUUID().UUIDString
let pathComponent = "\(UUID)-\(response.suggestedFilename!)"
return directoryURL.URLByAppendingPathComponent(pathComponent)
}
Dropbox.authorizedClient!.files.download(path: "/path/to/Dropbox/file", destination: destination)
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
print("bytesRead: \(bytesRead)")
print("totalBytesRead: \(totalBytesRead)")
print("totalBytesExpectedToRead: \(totalBytesExpectedToRead)")
}
.response { response, error in
if let (metadata, url) = response {
print("*** Download file ***")
print("Downloaded file name: \(metadata.name)")
print("Downloaded file url: \(url)")
} else {
print(error!)
}
}然后,您可以使用该原始进度信息来备份应用程序中的进度UI。
热门推荐
7 初八的祝福语简短
10 老婆生日祝福语简短孩子
11 生日祝福语简短而有深意
12 给舍友送祝福语简短
13 拜新年的祝福语简短
14 关于早晨的祝福语简短
15 讲课祝福语简短10字
16 红包祝福语简短网名
17 生日哥哥祝福语简短独特
18 同学道别祝福语简短