A. *_*ini 8 core-data uiimage nsdata swift
我的CoreData中有(n)个数据(UIImage JPEG)。
let imageData: [Data]...
Run Code Online (Sandbox Code Playgroud)
我已经有了这两个框架/ Pod:Zip和ZIPFoundation
我对此有一些疑问:
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)
}
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么 :(
Jon*_*ose -1
移动
self.createZipFile(urlArray: urlArray)
Run Code Online (Sandbox Code Playgroud)
到forEach循环之后。
| 归档时间: |
|
| 查看次数: |
142 次 |
| 最近记录: |