Search

Working with the Files App in iOS 11

Joseph Dixon

3 min read

Sep 13, 2017

iOS

Working with the Files App in iOS 11

iOS 11 is here and it brings a ton of exciting new features. One of Apple’s showcase features is the new Files app, which allows users to manage files stored locally and in iCloud. In this post, we learn how your app can take advantage of this cool new feature.

So You Want to Be a Poet

Let’s say you have created a great new app that encourages people to write more poetry. You’ve written several new poems and you’re excited to share them.

An app showing a collection of poems

Each poem created within your app is stored inside your app’s Documents folder as a simple text file. You’re excited about the new Files app in iOS 11 and you would like to give your users the ability to manage their poems from within Files. Naturally, you jump into the Files app to start managing your files.

Right away there’s a problem. Your poems do not appear in the Files app. Fortunately, there’s an easy fix.

Opting in with the Files App

Before your files can appear in the Files app, you must indicate that your app supports Open in Place and File Sharing Enabled. These options are configured using keys in your Info.plist file. The first key is UIFileSharingEnabled, which enables iTunes sharing of files in your Documents folder. The second key is LSSupportsOpeningDocumentsInPlace, which grants the local file provider access to files in your Documents folder. Add these keys to your Info.plist and set their values to YES.

  • UIFileSharingEnabled: Application supports iTunes file sharing
  • LSSupportsOpeningDocumentsInPlace: Supports opening documents in place

Run your app again to make these changes take effect. Congratulations! Your files should now appear in the Files app.

I See What You Did There

Now let’s take a look at your poems in the Files app. We can see all of our poems listed, but we also see a mysterious file named ‘Saves’.

files-with-saves

Understand that any files you place in your Documents folder will be visible within the Files apps. Apple suggests you only place user-created files in the Documents folder. Placing app-created files in the Documents folder will create clutter and confound your users.

Hiding Important Files

So where should you store your app-created files? It depends on their importance. Let’s say we placed the ‘Saves’ file in the Documents folder because we need to ensure it is backed up to iCloud. This file is important to the operation of our app, so backups are a must. This type of file should be placed in the Application Support directory instead. The Application Support directory is also backed up to iCloud, but it’s contents will not appear in the Files app. Let’s make this change.

// let documents = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let support = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!

If your file is not critical, or if it can be recreated easily, you should consider placing it somewhere else. The .cachesDirectory and FileManager.default.temporaryDirectory folders are good choices for files that aren’t critical to the operation of your app.

For the More Curious

As part of their Fall 2017 iPhone event, Apple posted a series of WWDC-esque videos. This post was inspired by their iOS Storage Best Practices video. The other videos cover topics like Apple TV 4K, Apple Watch Series 3, iPhone X and more.

Getting Ready for iOS 11

I hope this post helps you as you prepare your apps for the exciting new features in iOS 11. Keep an eye on our blog for other helpful iOS tips and tricks. If you need more in-depth help we provide comprehensive training and consulting solutions. Let’s work together to get your app ready for iOS 11.

Josh Justice

Reviewer Big Nerd Ranch

Josh Justice has worked as a developer since 2004 across backend, frontend, and native mobile platforms. Josh values creating maintainable systems via testing, refactoring, and evolutionary design, and mentoring others to do the same. He currently serves as the Web Platform Lead at Big Nerd Ranch.

Speak with a Nerd

Schedule a call today! Our team of Nerds are ready to help

Let's Talk

Related Posts

We are ready to discuss your needs.

Not applicable? Click here to schedule a call.

Stay in Touch WITH Big Nerd Ranch News