BAManagedDownloaderExtension
An application extension that uses the system implementation to schedule asset-pack downloads automatically.
Declaration
@protocol BAManagedDownloaderExtension <BADownloaderExtension>Overview
The protocol provides default implementations for all of the inherited BADownloaderExtension requirements.
Creating an Objective-C Downloader Extension
Xcode’s Background Download extension template generates Swift code when you select either the “Apple-Hosted, Managed” option or the “Self-Hosted, Managed” option, but you can easily switch to Objective-C instead if you prefer. To do so, follow these steps:
Remove
BackgroundDownloadHandler.swift.Create
DownloaderExtension.hwith the following contents:Apple Hosting
#import <StoreKit/StoreKit.h> @interface DownloaderExtension : NSObject <SKDownloaderExtension> @endSelf Hosting
#import <BackgroundAssets/BackgroundAssets.h> @interface DownloaderExtension : NSObject <BAManagedDownloaderExtension> @endCreate
DownloaderExtension.mwith the following contents:#import "DownloaderExtension.h" @implementation DownloaderExtension - (BOOL)shouldDownloadAssetPack:(BAAssetPack *)assetPack { // Use this method to filter out asset packs that the system would otherwise download automatically. You can also remove this method entirely if you just want to rely on the default download behavior. return true; } @endAdd
DownloaderExtension.mto your extension’s target.Add the following snippet inside your extension’s
Info.plist’sEXAppExtensionAttributesdictionary:<key>EXPrincipalClass</key> <string>DownloaderExtension</string>Check that the downloader extension’s target explicitly links the Background Assets framework under Frameworks and Libraries in the target editor’s General tab. If it doesn’t, then click to add an item to the list. Select “BackgroundAssets.framework” under Apple SDKs, then click Add.