In an app that saves data as an archive (NSKeyedArchiver), I am allowing users to export the .archive file to have a backup. Users can then re-import those files to retrieve backed up data.
Is there a way to restrict UIDocumentPickerViewController to only allow import of those .archive files? I tried using kUTTypeArchive as the only allowed type, but it doesn't appear to be the same kind of "archive", so I've used "public.item" while I look for a solution.
Running the mdls command on the file gives this file type: dyn.ah62d4rv4ge80c6xdrby1q3k
PS: If exporting and importing .archive files sounds like bad practice, I'm very interested to hear why!
The ".archive" file extension you use is not standard, it's an arbitrary file extension that you chose.
So your app should define its own custom file extension and UTI to represent your archive files. The fact that the file is created from using NSKeyedArchiver is irrelevant to the user.
Define your custom UTI and file extension under the Exported UTIs section. Then add it to the Document Types section as well.
Then use your custom UTI with UIDocumentPickerViewController so only files from your app with your app's custom extension are selectable.
Related
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)
I'm developing an app where people can download files, and have no problem downloading and saving them. The problem is, when some files are downloaded, they have no file extension (http://test.com/test, instead of http://test.com/test.zip), and I can't determine what kind of file they are. I've tried using NSHTTPURLResponse's suggestedFilename property, but that still doesn't put an extension on the file. So my question is, how do I know what kind of file something is without an extension? I've also tried getting the mime type of the file, but that didn't work.
I would like to create a file type with a personal extension by combining two other file types, like .mp3 and .pdf.
Later I need to re-open the custom files I've made and be able to use the included files in my app.
How do I do that on iOS?
One option is to append the data of the two files together. Include a few bytes of data at the start that tell you the size of each and maybe their original filenames. Then when you want to recreate the two files from the one custom one, you read your header to get the sizes and names, then use that info to recreate the original files.
Another option would be to zip the two files together. Just give the zip file your own custom extension.
Another option would be to use an NSFileWrapper. Include the two regular files in the wrapper.
I have associated a file type with my iOS app, so I can open files of that type in the app, e.g. from an email. Opening files works, but simply tapping on an attachment in an email opens the quick view screen, which comes up blank. The file format is a zip file with a custom extension, which I believe is unique.
What can I do to disable the quick view for my file type?
I hope you came up with a solution since :)
For people who may be searching for a solution too, have a look on the protocol(s) you custom type inherits from (array key UTTypeConformsTo, name "Conforms to UTIs")
In my case, my custom type is a zip archive with a custom extension (as you) and I put "public.data" and "public.archive".
The "public.archive" was responsible for the OS to display the content of my custom zip in Files app, or having the Quick look in Mail app.
The solution was to inherit only from "public.data".
I understand the basic of Document Interaction Programming and UIDocumentInteractionController and I've got it working in my app. However I'm having trouble with specific details of using custom file types. I can't find this addressed in the Apple docs anywhere.
My app uses it's own file types with unique extensions. The files themselves are just plists (xml), but I want the device to treat the files as only openable in my app. Originally I implemented the Document Interaction stuff to treat them as XML while I got it working, but now I want it to treat them as binary files that it needs to hand off to my app.
At the moment, if you have one of my files in an email attachment, iOS first shows the QuickLook (which just spews all the text content of the xml out) before you can choose to Open In. Similarly if one of my files is opened with Safari, Safari just shows the XML and doesn't give you the option to show it in my app at all.
So how do I get iOS to not treat my files as XML? I've changed the "Conforms to UTI" value and "public.mime-type" value in the info.plist, but it seems to have no effect.
Any tips greatly appreciated.
As far as i understand the UIT concept of Apple you cannot just change the file extension to change a potential UIT of the file. If the file contains XML-Data, other apps as well as internal apps might recognize your content and show it internally as XML.
Try to store your Plists with NSPropertyListSerialization NSPropertyListBinaryFormat_v1_0 (then you readble XML)
When you did that without success, why not trying this:
use zlib to compress the XML plists afterwards to a zipped file.
make a "unique" file extensions (<file>.myappname)
this should "hide" other apps and quick view.
Tell me if one of the ways did work for you.