Contents

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:

  1. Remove BackgroundDownloadHandler.swift.

  2. Create DownloaderExtension.h with the following contents:

    Apple Hosting

    #import <StoreKit/StoreKit.h>
    
    @interface DownloaderExtension : NSObject <SKDownloaderExtension>
    
    @end

    Self Hosting

    #import <BackgroundAssets/BackgroundAssets.h>
    
    @interface DownloaderExtension : NSObject <BAManagedDownloaderExtension>
    
    @end
  3. Create DownloaderExtension.m with 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;
    }
    
    @end
  4. Add DownloaderExtension.m to your extension’s target.

  5. Add the following snippet inside your extension’s Info.plist’s EXAppExtensionAttributes dictionary:

    <key>EXPrincipalClass</key>
    <string>DownloaderExtension</string>
  6. 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.

Topics

Downloading asset packs

See Also

Managed asset packs