压缩图像和文本文件并附加到Swift Mail Composer

时间:2018-07-14 05:17:26

标签: ios swift mfmailcomposeviewcontroller

实际上我有一个图像文件和文本文件。我想压缩两个文件,并作为附件添加到快速邮件编辑器中。有什么办法吗?请帮助

1 个答案:

答案 0 :(得分:0)

您可以使用

压缩文件

https://github.com/marmelroy/Zip

这里添加了示例代码

do {
    let filePath = Bundle.main.url(forResource: "file", withExtension: "zip")!
    let documentsDirectory = FileManager.default.urls(for:.documentDirectory, in: .userDomainMask)[0]
    try Zip.unzipFile(filePath, destination: documentsDirectory, overwrite: true, password: "password", progress: { (progress) -> () in
        print(progress)
    }) // Unzip

    let zipFilePath = documentsFolder.appendingPathComponent("archive.zip")
    try Zip.zipFiles([filePath], zipFilePath: zipFilePath, password: "password", progress: { (progress) -> () in
        print(progress)
    }) //Zip

}
catch {
  print("Something went wrong")
}

并将该zip附加到您的邮件编辑器

希望对您有帮助