MTOfflinePack
public actor MTOfflinePack
Represents a downloadable offline region.
-
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 )
-
createPack(region:Asynchronouscontext: ) 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 -> MTOfflinePackParameters
regionThe definition of the region to be downloaded.
contextOptional 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 -> MTPackStatsParameters
regionThe definition of the region to estimate.
Return Value
An
MTPackStatsobject containing the estimates. -
packs()AsynchronousRetrieves 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
MTOfflinePackinstances. -
cleanupExpiredPacks()AsynchronousCleans 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()AsynchronousDeletes all offline packs currently stored on disk.
Declaration
Swift
public static func removeAll() async throws
-
download(useBackground:Asynchronous) 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
WhenuseBackgroundistrue, this method returns after enqueuing tasks. The pack becomes loadable only after a later.completedstate change.Declaration
Swift
public func download(useBackground: Bool = false) async throwsParameters
useBackgroundIf 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 throwsParameters
useBackgroundIf true, the download will resume in a background URLSession.
-
refresh(useBackground:Asynchronous) Refreshes an expired pack, validating or updating its resources and resetting its expiration limit.
Declaration
Swift
public func refresh(useBackground: Bool = false) async throwsParameters
useBackgroundIf true, the download will be enqueued in a background URLSession.
-
cancel()AsynchronousCancels the ongoing download of the entire pack.
Declaration
Swift
public func cancel() async -
pause()AsynchronousPauses 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()AsynchronousDeletes the offline pack. This stops any ongoing downloads and removes all associated files and metadata from disk.
Declaration
Swift
public func remove() async throws