How to make a locked folder in iOS

I'm trying to make a folder in my app's documents folder that's locked or password protected so that only the app can access them. I've been searching but I'm not finding anything that will work. Can someone please point me in the direction I need to go.

Answered by KMT in 288753022

There are no traditional file level access rights schemes that transfer to that folder and it's contents that would persist and still remain functional to iOS.


You might find a way to lock it up, but then it would only be part of the payload, dead weight, unusable by your app proper, not a functional asset.


One alternative you might want to explore is a pwd protected zip. The pwd would be buried in your binary, then you could open a folder with files, read/write as needed/session based only, then zip back up. I haven't done this, but it's a concept that might serve your needs - keep in mind the time involved while all actions occur etc. I doubt it's bulletproof, but it might slow the script-kiddies down, at least.


Example:

SSZipArchive

func createZipFileAtPath(path: String!, withFilesAtPaths paths: [AnyObject]!, withPassword password: String!) -> Bool

You mean protected when the .ipa is opened on a computer?

It's possible for someone to get inside the app's docuements folder via iExplorer or iTunes File Sharing.

As with most security questions, the answer here really depends on the level of security you want. For example, if you just want to hide the file from iTunes file sharing, you can use a private documents directory per QA1699 Storing Private Data. You’ll probably want to prevent the file from being backed up, as discussed in QA1719 How do I prevent files from being backed up to iCloud and iTunes?.

IMPORTANT Naturally, you should only do this if the file only contain data that you can recover from elsewhere.

Beyond that things get substantially more complex. This effort is effectively a DRM scheme: you want to give something to the user but only allow them to use it in some specific way. Perfect DRM is theoretically impossible (unless you control the hardware) and, even if you ignore that, tricky to implement in practice. There’s always a balance to be struck between effectiveness, reliability, binary compatibility, and coding time.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I'm afraid I can't turn off iTunes file sharing. We already have hardware setup to record to the phone, but it requres iTunes file sharing to be on.

I'm afraid I can't turn off iTunes file sharing.

Hmmm. I didn’t suggest that you turn off iTunes file sharing. Rather, I suggested:

  • You should moves the items you don’t want visible to iTunes file sharing to a private documents directory, per QA1699

  • You disable backup on that items, per QA1719 (assuming that the data isn’t unique; if the data is unique, you really do want it backed up)

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
How to make a locked folder in iOS
 
 
Q