微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我已经创建了文件夹并将图像保存在该文件夹中。我希望该图像显示在照片中。我在下面编写了代码,希望图像/视频像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 举报,一经查实,本站将立刻删除。