Moving a package file of UIDocument class to iCloud - ios

I'm writing an app which saves and loads documents both locally and on iCloud. Locally is working fine, but I'm having a problem with iCloud.
The documents are saved as a package - the UIDocument reads and writes an NSFileWrapper which contains an image file, a thumbnail file, and an info plist. When I save the document to iCloud and then look at the files under 'Manage Storage', I see the individual files instead of the packages; and more importantly when I search for files using NSMetadataQuery it returns an NSMetadataItem for each of the individual files instead of the packages. As a result, my app doesn't realise there are any packages to load and iCloud is pretty useless.
I thought that if I set up the document type and exported the UTI correctly that the packages would be treated properly. Was that right? If so, what's the checklist for setting up a document type as a package?

I had fixed this issue by adding an object (add com.apple.package) in conforms to UTIs array (in plist file)

Related

Unable to Locate Realm File on Device

I am attempting to locate the realm DB file on my device (iPhone) and I followed the steps here and here. However, I do not see any realm files in the folder AppData/Documents.
I print out the URL path as I run the app on my device and my simulator, and this is what I see:
//On device
/private/var/mobile/Containers/Shared/AppGroup/C7332EE4-1567-4C96-8392-7FBD0DC9C863/DB/default.realm
//On simulator
/Users/MYNAME/Library/Developer/CoreSimulator/Devices/D205C50D-F432-4A1F-80CB-FB3D91E0A1EA/data/Containers/Shared/AppGroup/5E67A740-A338-4583-9B9D-461F5D1A734A/DB/default.realm
The URL written on the simulator appears to be any default URL where the Realm DB is written to. I can't seem to understand why can't I find the realm file at AppData/Documents on the actual device.
Realm files are only created on disk when you call Realm() for the first time. Once you've created an instance of Realm, you can find the exact file route of that Realm by printing out realm.configuration.fileURL. You can normally use Realm.Configuration to set a different location of the Realm file on disk as opposed to the Documents directory.
Both of those file paths you displayed show that the file is located in a folder named DB and it appears to be in an app group (eg, a shared folder between apps and extensions) instead of your app's default Documents directory.
So with that being said, it would appear that somewhere in your app, a custom Realm.Configuration object is being used to create the Realm file somewhere else, which would explain why you can't find it in Documents.

hidden files with .icloud extension in ubiquity container

I am building app which syncs documents over the iCloud.
When I create document (lets say its name is myfile1.doc) in one device and expect to appear in another one I get nothing - it looks like it doesn't sync. To my surprise when I read the content of Documents folder in ubiquity container I can see the representation of the file is added as a hidden file with .icloud extension (in this case .myfile1.doc.icloud).
I tried to find more about this .icloud files but so far no results.
Anyone know what are they representing? Is it the metadata item that indicates that file was added to iCloud and I should manually download it?
I think hidden files are handled by metadataQuery to indicate that the new file was added to iCloud and is waiting to be sync'ed. NSMetadataQuery recognizes them as representation of new files not yet downloaded to ubiquity container.
These files are not documented and you should ignore them. If you want to know what's in them, open one in a hex editor and have a look. Your code should not check for them or access them in any way.

iTunes File Sharing Clarification

I recently had my application rejected, by Apple for:
"Your app has the UIFileSharingEnabled key set to true in the Info.plist, but files and folders not intended for file-sharing are contained within its Documents folder..."
I am storing my application data in the documents directory, images and the core data database. This is a very simple progress, that allows the user to backup and import data. Below are the major steps:
The user can backup the data, which zips the folder.
The user can then use iTunes file sharing to take out the backup.
The user can import, the zip file which overwrites the data in the documents directory.
Has anyone else experienced similar issues? It seems like I am using this correctly.
You should put the zip file in the Documents folder, not any other files. The fact that you also put your core-data files (and some of the other files the user shouldn't see) in the Documents folder is why it was rejected.
You can store any files that the user shouldn't see in another folder such as the Application Support folder.

which directory should the download file be put

Since ios5, the file in the NSDocument would be upload to iCloud automatically, if the file in NSDocument is too large Apple would reject the app.
I want to know what path should I store the downloaded file, and what path to store un-completed file (Would not be deleted when application terminate)?
The Caches directory is suitable for files that can be replaced if they were to disappear. In other words, if the file you download can simply be downloaded again if it were to be deleted, then the Caches directory is a good place.
If the downloaded file isn't replaceable and the downloaded file is something that the user initiates as data for the app, then the Documents directory is actually a good place and shouldn't cause rejection.

Is it normal for iCloud's iOS "Manage Storage" settings to show the CONTENTS of file packages instead of the package names?

My app uses custom file packages (UTI conforms to com.apple.package) to store individual "notebooks", each package (directory) containing various individual files. I would expect the "Manage Storage" section of iCloud settings on my iPad to show the names of the packages, NOT the contents of these packages. It makes more sense for the user to be able to delete an entire "notebook" instead of the component files inside.
So is this normal, or did I do something wrong when I uploaded the package to iCloud? I've created and exported the UTI for my custom file type (and it seems to work, since the email app recognizes my new files and associates them with my app). Do I somehow have to tell iCloud about my UTI definition?
Finally, if this behavior is "normal", is there a way to force it to work like I want it to?
Thank you!
I think I discovered the answer by accident. I recently deleting all the iCloud data for my app from the iCloud settings -> Manage Storage page (by tapping "Edit" and then "Delete All"). After reloading my data back up to iCloud, it worked as I expected - I now see just the package filename, instead of all the contents of the package.
I suspect this is because I originally uploaded my data to iCloud before I properly defined the UTI. After I finished getting the UTI correct, I had my app delete the data and reload it, but this apparently wasn't as thorough as deleting the entire iCloud container via the "Manage Storage" page. My best guess is that when I FULLY deleted everything and reloaded it from scratch, the proper UTI export data went with it this time.
Anyway, it now works! I hope this can help someone else in a similar situation.

Resources