创建文件夹并在照片中保存图像/视频

问题描述

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...