问题描述
我已经创建了文件夹并将图像保存在该文件夹中。我希望该图像显示在照片中。我在下面编写了代码,希望图像/视频像WhatsApp一样显示。任何帮助将不胜感激。
try FileManager.default.createDirectory(atPath: newUrl!.path,withIntermediateDirectories: true,attributes: nil)
if isSent{
newUrl = newUrl?.appendingPathComponent("Sent")
}else{
newUrl = newUrl?.appendingPathComponent("Recieve")
}
try FileManager.default.createDirectory(atPath: newUrl!.path,attributes: nil)
let destinationFileUrl = newUrl?.appendingPathComponent(name)
let fileURL = url
let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig)
let request = URLRequest(url:fileURL!)
let task = session.downloadTask(with: request) { (tempLocalUrl,response,error) in
if let tempLocalUrl = tempLocalUrl,error == nil {
if let statusCode = (response as? HTTPURLResponse)?.statusCode {
print("Successfully downloaded. Status code: \(statusCode)")
DispatchQueue.main.async {
self.viewController?.view.makeToast("Image Downloaded")
}
}
FileManager.default.copyItem(at: tempLocalUrl,to: destinationFileUrl!)
}
task.resume()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)