I have a package-type document - i.e. it's really a folder, but it uses NSFileWrapper
and conforms to com.apple.package
to appear as a file - which I want to share by email. I've made an MFMailComposeViewController
and I'm trying to work out what to give to the first parameter of addAttachmentData:mimeType:fileName:
.
The package contains an image file and a plist, though that could change in the future.
How do I convert a package to data? Is that the right way of doing this?
As you said, a package is in reality a folder. It is interpreted as a package only on OSX operating systems.
As such, the mail protocol can't interpret it as a package / as a single file, and only sees a standard folder.
The only way to send this via email is to compress the files into a single file. You can do this by creating a ZIP archive of your package, or a tar.gz file for example.
There are multiple solutions to create a ZIP archive from code in Cocoa. You can use the libz library and C code directly, or use some third-party libraries (that already has generic code for it and helps you do this easier using Cocoa methods), like ZipArchive or others.