I have a problem sharing files between the OSX version of my app and the iOS version of the app when saving into the shared iCloud folder.
The iMac version can read any file from the shared folder. However the iOS version fails to read files saved from the OSX version.
When calling contentsOfDirectory on iOS
FileManager.default.contentsOfDirectory(at: mmFile.containerUrl!, includingPropertiesForKeys: nil, options: [])
I get Urls back like:
file:///private/var/mobile/Library/Mobile%20Documents/iCloud~xxx/Documents/Untitled.render-z, file:///private/var/mobile/Library/Mobile%20Documents/iCloud~xxx/Documents/.refract.render-z.icloud
Where the first file was saved on iOS and loads correctly, the second from OSX which has a "." prefix and a ".icloud" postfix and cannot be loaded.
I save the files with the same code:
stringData.write(to: url(), atomically: true, encoding: .utf8)
The encoding does not matter, its the same behavior if I use .ascii or .utf8 etc.
When I try to read such a file in iOS I get content back like
bplist00Ó\NSURLNameKey_NSURLFileSizeKey_NSURLFileResourceTypeKey_2spheres.render-z
I cannot figure this out! All the entitlements and plist properties seem to be correct and sharing the iCloud DB works fine too.