BAURLDownload failed on inaccurate fileSize when non-essential

Hi everyone, I'm integrating BackgroundAssets into my app and run into the following issue. According to the docs fileSize only needs to be accurate for essential downloads

    /// @abstract Constructs a download object to represent the download of a asset located inside of the provided @c request.
    /// @param identifier A unique identifier that is used to track the download across the app and extension.
    /// @param request The request used to perform the download. The URL provided inside of the request must be a https scheme.
    /// @param essential Whether the download is essential. See @c BADownload.isEssential. Default is false.
    /// @param fileSize The size of the file to download. For Essential downloads, this field must be accurate in order to show the user
    /// accurate progress during app installation. If the size does not match the file being downloaded, then the download will fail. It is recommended to
    /// report an accurate @c fileSize for both Essential and Non-Essential downloads.
    /// @param applicationGroupIdentifier The identifier of the application group that should used to store the finished download.
    /// @param priority A priority between @c BADownloaderPriorityMin - @c BADownloaderPriorityMax which is used to order the downloads for this process.
    /// It is recommended to use  @c BADownloaderPriorityDefault if download priority does not matter.
    @available(iOS 16.4, *)
    public init(identifier: String, request: URLRequest, essential: Bool, fileSize: Int, applicationGroupIdentifier: String, priority: BADownload.Priority)

However, when I'm queueing up non-essential downloads with inaccurate fileSize, my BADownloadManagerDelegate gets a failedWithError callback, with error

The download failed because the file size provided does not match what was downloaded.

This happens for me when the app needs to download a new version of the manifest, which contains the information about all the other background assets that needs to be processed.

Is the documentation wrong and fileSize must always be accurate, even for non-essential downloads? All help is appreciated to resolve this.

  • Upon further experimentation I've discovered that you must set fileSize to 0 to make the BAURLDownload function as expected. Setting it to -1, or slightly different filesize will yield a download failure. So setting both fileSize to 0 and essential to false is required to download assets that you don't have a proper filesize for.

Add a Comment

Replies

@GeertB is correct, you may set it to 0 for non-essential downloads to bypass this restriction. We'll update the header documentation, thanks for bring this to our attention.