iOS on-demand resources and on-boarding
On-demand resources are not just useful for games. Learn how to take advantage of it for your application’s on-boarding.

When users open your app for the first time, it must be memorable. When we built Unsplash for iOS, we wanted to show a short guide to explain a couple of the features of the app. It was clear we had to show beautiful photos from our community to illustrate that guide.

The on-boarding was initially fetching photos from the API. It was cool because it displayed fresh content every time. But it looked empty and broken if you had a poor connection –or worse, no connection at all– and I had to consider either showing a spinner or an error message. That’s not a good experience when you open the app for the first time.
The safer solution is to embed the photos in the app. But it takes disk space for something that users will see only once; it’s wasteful. Having no choice though, I reluctantly resorted to that solution. I wanted to use enough photos so that it doesn’t look too repetitive; they ended up taking about 20 MB. That’s 20 MB too much for a one-time thing.
On-demand resources
Apple introduced on-demand resources in iOS 9. It enables apps to load assets dynamically. You assign tags to some assets, then when you upload a build to the App Store, Apple hosts the tagged assets so that they are downloaded separately from the app. The app requests the assets when required, and can discard them when they are not needed anymore. This is a great way to save space on devices.
Most of the examples for this feature use games to explain it. When you download a game, you don’t need Level 5 right away. The app can be downloaded with Level 1 and 2; then when you complete Level 1, the app can discard it and download Level 3, and so on.
What’s the deal with on-boarding?
It turns out that we can specify some assets to be in a group called Initial Install Tags. Assets in that group are downloaded alongside the app so that they are available on the first launch. Perfect for on-boarding.
So I tagged all the images used in the on-boarding.

Then I added that tag to Initial Install Tags.

Finally, I added a bit of code to load and discard the assets.
private lazy var bundleResourceRequest = NSBundleResourceRequest(tags: Set([“Onboarding”])) | |
private func loadOnDemandAssets() { | |
bundleResourceRequest.conditionallyBeginAccessingResources { [unowned self] (available) in | |
if available { | |
self.loadOnboardingAssets() | |
} else { | |
self.bundleResourceRequest.beginAccessingResources { (error) in | |
guard error == nil else { return } | |
self.loadOnboardingAssets() | |
} | |
} | |
} | |
} | |
private func discardOnDemandAssets() { | |
bundleResourceRequest.endAccessingResources() | |
} |
As you can see, it’s effortless to implement on-demand resources, and it’s a great solution for on-boardings.
Documentation: On-Demand Resources Guide: On-Demand Resources Essentials
All the photos used in the on-boarding: https://unsplash.com/collections/1819512/unsplash-for-ios-on-boarding