Update assets in the background

I am looking to automatically fetch some new (and large) content in the background while the app is closed. The content that needs to be downloaded is user specified, and as such doesn't need to run on install or update, but only periodically to see if the content has been updated.

The app is a mac app, and I wanted to know if Background Assets is a good choice for this, as the app may not always be running, and I'd like for the user's content to be updated seemingly when they open the app.

If this is the right course of action, what is a recommended way of implementing this?

I was thinking of scheduling a request to check for updated assets in BADownloaderExtension.download() and then checking in BADownloaderExtension.backgroundDownload(_:finishedWithFileURL:) if are new content, and then schedule the download of new content or if it is new content then installing it appropriately from there.

Thank you

- Bastian

Replies

BackgroundAssets is perfect for this use-case. On macOS the extension is given runtime despite the app being terminated. On iOS we require that the app wasn't terminated by the user for the extension to be given runtime.

You'd use the BAManifestURL to download a catalog/manifest that contains URLs to content you may want to download. You'd parse the manifest in the extension to know if there is anything to download. From there you'd return all the downloads you'd need in:

func downloads(for contentRequest: BAContentRequest, manifestURL: URL, extensionInfo: BAAppExtensionInfo) -> Set<BADownload>