我的CoreData中有(n)个数据(UIImage JPEG)。
let imageData: [Data]...
我已经有了这两个框架/ Pod:Zip和ZIPFoundation
我对此有一些疑问:
我需要为每个imageData创建一个临时URL吗?
如果是,我必须tempURL.appendingPathExtension("jpg")
在呼叫之前或之后添加到每个临时URL data.write(to: tempURL)
。
在那之后,我有了一个URL数组,所以我只需要创建一个Zip文件并共享它。但这不起作用,我的Mac上出现一个.zip-.cpgz循环。
private func createURLsFrom(imageData: [ImageData]?) { var urlArray = [URL]() imageData?.forEach { imData in if let data = imData.imageData, let tempURL = NSURL.fileURL(withPathComponents: [NSTemporaryDirectory(), NSUUID().uuidString])?.appendingPathExtension("jpg") { do { try data.write(to: tempURL) urlArray.append(tempURL) } catch {...} } } self.createZipFile(urlArray: urlArray) } private func createZipFile(urlArray: [URL]) { if let zipURL = try? Zip.quickZipFiles(urlArray, fileName: "ZIP_Test1") { self.sendEmailWith(dataURL: zipURL) } else {...} } private func sendEmailWith(dataURL: URL) { if MFMailComposeViewController.canSendMail() { let mailComposer = MFMailComposeViewController() mailComposer.mailComposeDelegate = self mailComposer.setSubject("setSubject") mailComposer.setMessageBody("setMessageBody", isHTML: false) mailComposer.addAttachmentData(dataURL.dataRepresentation, mimeType: "application/zip", fileName: ("ZIP_Test1.zip")) self.present(mailComposer, animated: true, completion: nil) } }
我究竟做错了什么 :(