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.
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.
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.
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
Run your app again to make these changes take effect. Congratulations! Your files should now appear in the Files app.
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’.
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.
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
FileManager.default.temporaryDirectory folders are good choices for files that aren’t critical to the operation of your app.
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.
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.
Interested in learning more about our basic and advanced iOS Courses?
Learn from the experts at a Big Nerd Ranch Bootcamp!
Interested in leveling up your coding skills from the same authors of the Big Nerd Ranch Guide? Subscribe to The Frontier today!
Chris Downie and Sam Landfried
Chris Downie and Sam Landfried