Jan Jan - 1 month ago 11
Swift Question

files saved as package (with filewrappers) and icloud drive, are they zipped when emailed?

I have an app which uses UIDocument and writes data using filewrappers:

public override func contents(forType typeName: String) throws -> Any {
print("******writing the contents******")
print("**** typeName = \(typeName)")
let result = FileWrapper(directoryWithFileWrappers: [:])
... lots more....

This actually works fine. I also have in my plist the uti of the document. The document can be saved, copied to icloud drive, imported back in to the app, so far so good....

But now the hard part: Icloud drive has an email button. If I mail a working file via that button to myself, and save the file on the mac, the right click menu option "show package contents" is gone. (While it is there for the same file in icloud drive).

Also, if i try to open this mail attachment on the iphone, my app is unable to find a subpath into the wrapped file. (so my file is called bla.myextension, and metadata is supposed to be at bla.myextension/meta.xml but the file which is in Inbox appears to be a "file" rather than a directory.

What is happening. Is the email somehow automatically zipping things up?

Jan Jan

The file indeed is zipped automatically. So in application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) just check if the result is a directory, because opening from icloud drive may give you unzipped results. If it is a directory then you have to unzip it yourself.

            var isDir : ObjCBool = ObjCBool( false)
            if fileManager.fileExists(atPath: url.path, isDirectory: &isDir) {
                if isDir.boolValue {
                    ...copy directory...
                else {
                    ...unzip and copy....