MTOfflinePack

public actor MTOfflinePack

Represents a downloadable offline region.

  • id

    The unique identifier of the pack.

    Declaration

    Swift

    public nonisolated let id: String
  • The region definition of the pack.

    Declaration

    Swift

    public nonisolated let region: MTOfflineRegionDefinition
  • The current progress of the pack download.

    Declaration

    Swift

    public private(set) var progress: MTOfflinePackProgress { get }
  • The metadata object linking state and region.

    Declaration

    Swift

    public private(set) var metadata: MTOfflinePackMetadata { get }
  • An optional delegate to receive download notifications.

    Declaration

    Swift

    public weak var delegate: MTOfflineDownloadDelegate?
  • If true, download progress updates will be reported to the delegate. Defaults to false.

    Declaration

    Swift

    public var isProgressReportingEnabled: Bool
  • The current state of the pack download.

    Declaration

    Swift

    public private(set) var state: MTOfflinePackState { get set }
  • The date when the pack expires.

    Declaration

    Swift

    public var expiresAt: Date { get }
  • Returns true if the pack has passed its expiration date.

    Declaration

    Swift

    public var isExpired: Bool { get }
  • Sets the delegate to receive download notifications.

    Declaration

    Swift

    public func setDelegate(_ delegate: MTOfflineDownloadDelegate?)
  • Enables or disables progress reporting.

    Declaration

    Swift

    public func setProgressReportingEnabled(_ isEnabled: Bool)
  • Initializes a new pack to begin downloading.

    Declaration

    Swift

    public init(
        region: MTOfflineRegionDefinition,
        context: Data? = nil
    )

Static Methods

  • Creates a new offline pack and initializes its on-disk storage and metadata.

    Throws

    An error if directory creation or metadata persistence fails.

    Declaration

    Swift

    public static func createPack(
        region: MTOfflineRegionDefinition,
        context: Data? = nil
    ) async throws -> MTOfflinePack

    Parameters

    region

    The definition of the region to be downloaded.

    context

    Optional custom data (e.g., JSON) to attach to the pack metadata.

    Return Value

    A newly initialized MTOfflinePack.

  • estimateSize(region:) Asynchronous

    Estimates the pack size for a given region definition.

    Throws

    An error if style fetching or parsing fails.

    Declaration

    Swift

    public static func estimateSize(region: MTOfflineRegionDefinition) async throws -> MTPackStats

    Parameters

    region

    The definition of the region to estimate.

    Return Value

    An MTPackStats object containing the estimates.

  • packs() Asynchronous

    Retrieves all offline packs currently stored on disk. The packs are stably sorted by their creation date (oldest first).

    Declaration

    Swift

    public static func packs() async throws -> [MTOfflinePack]

    Return Value

    An array of MTOfflinePack instances.

  • cleanupExpiredPacks() Asynchronous

    Cleans up packs that have been expired for longer than the grace period. This permanently deletes the packs and their files from the disk.

    Declaration

    Swift

    public static func cleanupExpiredPacks() async throws
  • removeAll() Asynchronous

    Deletes all offline packs currently stored on disk.

    Declaration

    Swift

    public static func removeAll() async throws

Download Actions

  • Starts the download process for this pack. This generates the necessary manifest based on the pack’s region definition and then begins downloading all required resources.

    Note

    When useBackground is true, this method returns after enqueuing tasks. The pack becomes loadable only after a later .completed state change.

    Declaration

    Swift

    public func download(useBackground: Bool = false) async throws

    Parameters

    useBackground

    If true, the download will be enqueued in a background URLSession.

  • resume(useBackground:) Asynchronous

    Resumes a previously paused or failed download.

    Declaration

    Swift

    public func resume(useBackground: Bool = false) async throws

    Parameters

    useBackground

    If true, the download will resume in a background URLSession.

  • Refreshes an expired pack, validating or updating its resources and resetting its expiration limit.

    Declaration

    Swift

    public func refresh(useBackground: Bool = false) async throws

    Parameters

    useBackground

    If true, the download will be enqueued in a background URLSession.

  • cancel() Asynchronous

    Cancels the ongoing download of the entire pack.

    Declaration

    Swift

    public func cancel() async
  • pause() Asynchronous

    Pauses the ongoing download of the entire pack.

    Declaration

    Swift

    public func pause() async
  • cancelAsset(id:) Asynchronous

    Cancels the download of a specific asset within the pack.

    Declaration

    Swift

    public func cancelAsset(id: String) async
  • remove() Asynchronous

    Deletes the offline pack. This stops any ongoing downloads and removes all associated files and metadata from disk.

    Declaration

    Swift

    public func remove() async throws