• iOS
  • Swift
  • CallKit

When Reverse AU has downloaded a list iOS has yet to use

How Reverse AU tracks downloaded and applied Call Directory versions separately so it can recover after a failed reload.

The call labelling and blocking list in Reverse AU goes through two steps. The app downloads the data into an App Group, then asks iOS to run the Call Directory extension and load it. An App Group is storage that both the app and the extension can read. An extension is a small program that ships inside the app but runs separately, when iOS asks for it. Call Directory is the extension type iOS calls for the list used on incoming calls; it is part of CallKit, Apple’s framework for call-related features. Apple’s App Group guide describes how an app and its extension share a container. Those steps can have different outcomes. The file can already be on disk when iOS rejects the reload because the extension is disabled. If both steps share one “current version” field, the next sync can see that it matches the server and skip the work that is still pending.

Two version markers

Reverse AU keeps downloadedVersion for the data on disk and appliedVersion for the version iOS has confirmed loading. The app verifies the download’s hash, a short fingerprint computed from the file’s bytes that changes if any byte is wrong, and decompresses it into a temporary file. Once the files are ready, it writes state.json atomically. The extension reads that state file to decide which snapshot to open. A snapshot contains the complete list for a specific version. An atomic state-file update lets the extension read a complete state.json even if it runs while the app is replacing the file.

Point in the sync Downloaded Applied
Before syncing A A
Snapshot B is ready, waiting for iOS B A
iOS confirms the reload B B

If the reload fails, the two versions stay at B and A. If the server is still on B and the snapshot is still on disk during the next check, the app can ask iOS to reload in full from the existing file without another download.

A delta needs the right starting point

A delta describes only the entries that changed between two versions. For example, the change from A to B might contain one new label and one entry to remove. If iOS has a list older than A, those two operations cannot bring it up to B.

When a suitable delta chain is available, the app merges it into the new snapshot and stages a separate file of pending changes for the extension. The extension uses that file only when CallKit requests an incremental load, the file exists, its endpoints match the versions in the state file, and the blocking settings still match what was applied. CallKit defines incremental data as changes relative to the last list loaded by the system. If any condition fails, the extension reads the full snapshot. CallKit incremental-load documentation

The blocking settings are part of the starting point. Changing the report threshold, for example, can change whether numbers outside the delta should be blocked. So when the app saves a new setting, it discards the pending delta and reloads from the snapshot.

Keep the retry path simple

Background refresh downloads deltas only. If a full snapshot download is needed, the app waits until it returns to the foreground. A rejected reload also sends the next attempt through the full-load path. That gives the snapshot two jobs: it supports the first load and provides a recovery path later.

I came away with a simple rule for work split across processes. The app can confirm a file is on disk. CallKit’s result tells the app whether the directory has loaded. Tracking both lets the retry pick up where the previous attempt left off. Trang Trắng 2.x reuses this sync code; its upgrade from 1.0.x keeps the Call Directory bundle ID and starts with a full snapshot load.

Conclusion

Keep “downloaded” and “applied” as separate facts whenever one process prepares data and another system must load it. Retry from the saved snapshot when iOS has not confirmed the new version, and use a delta only when its starting version matches the one CallKit has loaded.

Written by Duy Pham Independent developer. I build the apps on this site and write about how they work.

More about me