# Update Offline Map Packages

The SDK does not download regional updates automatically. Use this guide to periodically check the online map catalog for newer region versions and install replacement packages when an update is available.

```swift
private func isNewer(remote: String?, than local: String?) -> Bool {
    return NGLRegionalOfflineVersionIsNewer(remote, local)
}
 
func checkForUpdates() {
    let installed = NGLRegionalOffline.listInstalledRegions()
    let localById = Dictionary(
        uniqueKeysWithValues: installed.map { ($0.regionId, $0) }
    )
 
    NGLRegionalOffline.fetchRegionList {
        [weak self] catalog, error in
        guard let self, error == nil else { return }
 
        for remote in catalog ?? [] {
            guard let local = localById[remote.regionId] else { continue }
 
            if isNewer(remote: remote.version, than: local.regionVersion) {
                // remote.regionId has an update.
            }
        }
    }
}
```

If the service does not provide a stable version string, use timestamp only according to the service contract. Do not detect updates by comparing file sizes alone.

### Install a full replacement update

Use the following script for a complete replacement of an installed offline package:

```swift
NGLRegionalOffline.downloadRegion(
    withId: regionId,
    clearBefore: true
) { [weak self] error in
    if let error {
        self?.handleRegionalOfflineError(error)
    }
}
```

The update is complete only when the progress listener reports `.completed`.

For package-level update detection:

1.  Call _fetchRegionDetail(forRegionId:)_ to obtain the latest online `tarList`.
    
2.  Call _loadDetail(forRegionId:)_ to obtain the locally cached details.
    
3.  Index the packages by `tarName`.
    
4.  Treat added packages, removed packages, or changed package versions as a regional catalog update.
