1

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!

Kqtr
  • 5,824
  • 3
  • 25
  • 32
  • Well it sounds like the idea of a .archive file is just something you made up. So you’d need to export the type in your Info.plist. – matt Aug 20 '18 at 18:18
  • Thank you matt, I had no idea it was arbitrary! Learned that in a book years ago and they used .archive, I assumed I had to too. – Kqtr Aug 20 '18 at 20:19

1 Answers1

1

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.

Kqtr
  • 5,824
  • 3
  • 25
  • 32
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Thank you! Looks like I actually haven't properly understood what an archive was. Is the ".archive" extension that I use (taken from a book) actually arbitrary, and I could change it to the custom file extension I'll create for the app? – Kqtr Aug 20 '18 at 20:09
  • Yes, the `.archive` extension is arbitrary. – rmaddy Aug 20 '18 at 20:11
  • You should definitely use a file extension that’s app-specific instead. This file extension is definitely super generic and should not be tied to any specific app... – Thomas Deniau Aug 22 '18 at 08:55