gpt4 book ai didi

swift - 如何获取用户目录中的下载文件的url?

转载 作者:行者123 更新时间:2023-11-30 14:04:51 28 4
gpt4 key购买 nike

如何获取文件的url?或者查看用户目录中有哪些文件?

   let destination = Alamofire.Request.suggestedDownloadDestination(directory: .UserDirectory, domain: .UserDomainMask)
Alamofire.download(.GET, "http://best-muzon.com/dl/NNE2IxI6LYNtocG2fmFn3Q/1442201485/songs12/2015/02/vremja-i-steklo-imja-505-(best-muzon.com).mp3", destination: destination)
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in

dispatch_async(dispatch_get_main_queue()) {
//print("Total bytes read on main queue: \(totalBytesRead)")
self.label.text = String(totalBytesRead)
}
}
.response { request, response, _, error in
}
`

最佳答案

您拥有目标目录 - .UserDirectory 参数 - 和文件名 - URL 的最后一个路径部分

let url = "http://best-muzon.com/dl/NNE2IxI6LYNtocG2fmFn3Q/1442201485/songs12/2015/02/vremja-i-steklo-imja-505-(best-muzon.com).mp3"
let fileName = url.lastPathComponent

我不知道 .UserDirectory 是主文件夹 (~) 还是下载文件夹 (~/Downloads),但连接目录和路径并创建文件 URL 很容易

let destinationPath = NSHomeDirectory().stringByAddingPathComponent(fileName)

let destinationPath = NSHomeDirectory().stringByAddingPathComponent("Downloads/\(fileName)")

let destinationURL = NSURL(filePath: destinationPath)!

关于swift - 如何获取用户目录中的下载文件的url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32553259/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com