我已经创建了文件夹并将图像保存在该文件夹中。我希望该图像显示在照片中。我在下面编写了代码,希望图像/视频像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, withIntermediateDirectories: true, 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()