Track the progress and state of an offline pack download - Swift SDK

The MapTiler SDK for iOS provides a powerful Offline Pack API that allows you to track the progress and state of an offline pack download.

To track the progress and state of an offline pack download, you must implement the MTOfflineDownloadDelegate protocol and enable progress reporting.

Before you begin, ensure you have followed the iOS Getting Started with Offline Pack API to set up your project and obtain your API key.

Tracking download progress


import MapTilerSDK

class DownloadObserver: MTOfflineDownloadDelegate {
    func offlinePack(_ pack: String, didChangeState state: MTOfflinePackState) {
        print("Pack \(pack) state changed to: \(state)")
    }

    func offlinePack(_ pack: String, didUpdateProgress progress: MTOfflinePackProgress) {
        let percent = String(format: "%.1f", progress.percentage * 100)
        print("Download progress: \(percent)% (\(progress.downloadedResources)/\(progress.totalResources) resources)")
    }

    func offlinePack(_ pack: String, didFailResource error: MTOfflineError, context: MTOfflineContext) {
        print("Resource failed: \(error)")
    }

    func offlinePack(_ pack: String, didSucceedResource context: MTOfflineContext) {
        // Resource downloaded successfully
    }
}

// Create your observer
let observer = DownloadObserver()

Task {
    do {
        // Create the pack (assuming `definition` is already created)
        let pack = try await MTOfflinePack.createPack(region: definition)
        
        // Set the delegate and enable reporting
        pack.setDelegate(observer)
        pack.setProgressReportingEnabled(true)
        
        // Start download
        await pack.download()
    } catch {
        print("Error: \(error)")
    }
}

Learn more

For more information browse our API Reference

Check out our SDK Swift Examples.

Was this helpful?
Mobile SDK
iOS
Track the progress and state of an offline pack download - Swift SDK
Tracking download progress