Check out Meet Background Assets from WWDC 2022
Feature Recap
- Designed to prevent waiting when launching your app, use a framework and App Extension to download out-of-band content via a CDN or managed server
- It will download content that can be placed in your app’s sandbox for use by the app
- Supported on macOS, iOS, and iPadOs
- Can run periodically in the at install time before user runs the app, background, or when the app is not running
- There are time limits on the run to optimize battery life
- Consider memory mapping your data as you are also limited to amount of memory used by your app
- The extension can be throttled if the app is not used very often
- The Background Asset manager is prefixed with BA
- User can turn off background app refresh turned off or is in low power mode – your extension will not run.
- BADownloadManager is a singleton that can be used throughout your app.
- All downloaded assets are marked pursuable by default. If you increase their size after download, they will be marked non-purgeable
What’s New
- Essential downloads – will be integrated into the system and will stop the user from loading the app. They occur during app install. These downloads have priority over normal background downloads.
- Non-Essential downloads will be automatically launched after essential downloads are ready. Note the UI changes that shows which part of the install download is App, App Install, and Essential assets.
- If a user turns off In-App Content the you will not get essential downloads to download automatically. You will need to code your application to handle download these assets different.
- You can convert an essential download to a non-essential download, and the re-enque this download
- Also you need to setup your info.plist
Sample Implementation
- First add your required info.plist keys
- Create your App Extension
- Make sure your app extensionMakes and app are both using the same team identifier
- Make sure to use .withExclusiveControl for your download session
- Promoting from background to foreground does not restart the download, it just continues from where it was at a higher priority.
- Always use move objects to move the finished download in to the app package
- So far none of my apps have a need for these features.. but I do have a few game ideas which may need this in the future. So definitely keeping this in my back pocket
Debugging Guidance
- Since the extension launches during the install or periodic system events. You must use a tool called “xcrun backgroundassets-debug” in a terminal to be able to debug with a device paired with your Mac. The device must be in Developer Mode
- You can now trigger events to see how the app or extension behaves.