【问题标题】:Compressing image and text file and attaching to swift mail composer压缩图像和文本文件并附加到 swift 邮件编辑器
【发布时间】:2018-07-14 05:17:25
【问题描述】:

实际上我有一个图像文件和文本文件。我想压缩这两个文件并作为附件添加到 swift mail composer。任何解决方案?请帮忙

【问题讨论】:

标签: ios swift mfmailcomposeviewcontroller


【解决方案1】:

你可以用这个压缩你的文件

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 附加到您的邮件编辑器

希望对你有帮助

【讨论】:

  • 如果我们从正确的文件夹中获取文件,解决方案很好。但我在项目本身和图像中也有文件。怎么可能压缩?请帮忙
  • @Rakesh 你可以轻松做到。您只需将文件临时保存在文档目录中,然后使用 zip 完成即可从该位置删除。
  • 最好使用文件系统,因为它会减少内存的负载,因此将来出现内存问题的可能性最小
  • 这个 pod 只有 swift 4。它在 swift 3 中工作吗?如文档中所述,它适用于 swift 4
  • @Rakesh 我不确定您使用的是哪个版本的 xcode?​​span>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多