Guided tour¶
Offline Tasks calls every part of the library's public API from a screen you can see, so this page is the API told as an app: each screen, what it shows, the calls behind it, and the page that explains each call. Every call sits in the samples' data layer, and the docs pages show those very lines. The Android and iOS samples are one product; where they differ, the table says so. After the screens, a ten-minute walk through the app shows the library at work, with your project's dashboard open beside it.
Two things hold on every screen. The client is built once, with every setting written out at its default, and the app's own connectivity signal (Configuration). Every failure a call can throw goes through one mapping, a sentence for each kind (Failures and the rejected list).
Tasks¶
The list, open tasks first, with a search field and four chips above it.
| What it shows | The calls | On iOS | Explained on |
|---|---|---|---|
| The list, live, with a cloud mark on each row whose change waits | selectAsFlow, with CacheFirstThenNetwork, or NetworkFirstThenCache while the Sync tab's Prefer fresh data is on; each emission's pendingRowKeys |
selectAsSequence, with .cacheFirstThenNetwork or .networkFirstThenCache; pendingMutations(table: "tasks") |
Reactive reads, Optimistic overlay |
| Search, and the All / Open / Done / Recent chips, as filters the server applies | ilike on the title; eq and is on done; Recent as gte and lt on created_at in one and group |
ilike; neq and is on done; Recent as gte and lt, which Swift sends in one group by itself |
Reactive reads, One-shot reads |
| How many photos each task has | A live read of the photo rows with in on task_id |
in("task_id", values:) on the live read |
Reactive reads |
| Pull to refresh, and the caption under the title: "Updated just now", "From this device, 3 minutes ago", and how many changes wait | select(readStrategy = NetworkFirst(maxAge)) of the list shown, chip and search included, since each query is cached on its own, and the result's isFromCache, fetchedAt and hasPendingMutations |
select(readStrategy: .networkFirst(maxAge:)), and the OfflineResponse's isFromCache, fetchedAt and hasPendingMutations |
One-shot reads |
| Tick a task done | update with a JSON body |
update with a [String: OfflineJSON] body |
Writes and the offline queue |
| Swipe a task away, with Undo | Its photos still waiting to upload, discarded first (waiting for one on its way); its photo files (online only), one that landed meanwhile too; its refused uploads; then delete of its photo rows and of the task |
The same, with no Undo | Writes and the offline queue, Storage caching |
| Mark all done, in the menu | rpc("complete_all_tasks"), a database function, network only; then the list shown and the whole list are read again, since a function's changes reach the device only by a read |
rpc("complete_all_tasks"), from the Tasks tab's menu |
Coming from supabase-kt |
| An alert when the server refused a waiting change | rejectedMutations().first() at launch, then the flow |
The same | Failures and the rejected list |
| The badges: open tasks on Tasks, waiting changes on Sync, red when one was refused or conflicts | select(readStrategy = CacheFirst(maxAge)) at launch, then the live list; syncStatus, shown once isQueueCounted |
select(readStrategy: .cacheFirst(maxAge:)) at launch, then the live list; syncStatus, shown once isQueueCounted |
One-shot reads, Replaying the queue |
New task¶
| What it shows | The calls | On iOS | Explained on |
|---|---|---|---|
| Title, notes, and Needs a connection | insert(row, mutationStrategy) { select() }: QueueIfOffline, the default, or OnlineOnly with the switch on, whose stored row the app then puts in the cache with applyServerRecord, since an online-only write is never patched in |
insert(row, mutationStrategy:).select().single(): .queueIfOffline or .onlineOnly, then applyServerRecord of the stored row |
Writes and the offline queue |
| "Saved at 10:42", or "saved on this device" | MutationOutcome.Applied.result, the row the server stored, or Queued |
MutationOutcome.applied(result:), the row the server stored, or .queued(pendingMutation:) |
Writes and the offline queue |
| Add photo, several at once, with their thumbnails, online or offline | None at first: once the task is saved, each photo is added as Task detail adds one | The same, with a PhotosPicker of up to ten photos; a task that needs a connection and is not saved files none |
Storage caching |
Task detail¶
| What it shows | The calls | On iOS | Explained on |
|---|---|---|---|
| The task, even one never opened before, offline | The list's own query, with the row picked out on the device | The same | FAQ |
| Title and notes, saved as you type | update with a typed value |
update with a typed Encodable patch that writes a cleared note as null |
Writes and the offline queue |
| Duplicate task, in the menu | upsert(row) { select() }, then isQueued and resultOrNull() |
upsert(copy), under an id made from the task's, so a second copy writes over the first; then isQueued |
Writes and the offline queue |
| Delete task, the bin beside the done button, offline too | As swiping a task away | The same, from the last row of the task's form | Writes and the offline queue |
| The photos; with Simulate offline on, "Showing photos saved on this device" | selectAsFlow of the photo list, FlowReadStrategy.CacheOnly while network access is off |
selectAsSequence of the photo list, .cacheOnly while Simulate offline is on |
Reactive reads |
| Add photo, online or offline: the photo shows at once from the device, marked "Waiting to upload" (online while it uploads), or "Upload failed" with Retry and Remove | upload(path, jpeg, QueueIfOffline) on a bucket without a header, then insert of the photo's row, queued behind it; the marks from storage.pendingUploads() and storage.rejectedUploads(), Retry retryRejectedMutation, Remove discardPendingMutation or dismissRejectedMutation; an upload that fails as it is sent online is kept by the app, failed, with Retry and Remove |
In the task's Photos section, with no progress: the uploader follows syncStatus, then exists(path:) (on a retry), upload(_:data:options:) with UploadOptions (contentType, upsert, userMetadata), upsert(_:onConflict:ignoreDuplicates:) of the row and ensureCachedFile(path:) |
Storage caching |
| Share all photos of this task, in the menu | createSignedUrls |
createSignedURLs(paths:expiresIn:) |
Storage caching |
Photo viewer¶
| What it shows | The calls | On iOS | Explained on |
|---|---|---|---|
| The photo, offline too | ensureLocalUri; the thumbnails before it, localUriIfCached |
cachedFile, else ensureCachedFile, read from CachedFile.url |
Storage caching |
| Details: in the bucket or not, size, type, times, ETag, the public and authenticated URLs, and the copy on this device | exists, info, publicUrl, authenticatedUrl, cachedFile and its fetchedAt and sizeBytes |
exists, info, publicURL, authenticatedURL, cachedFile and its fetchedAt, sizeBytes and path |
Storage caching |
| Share | ensureLocalFile, copied out of the cache for the share sheet |
ensureCachedFile's CachedFile.url, handed to the share sheet |
Storage caching |
| Share link: a copy 512 pixels wide, for an hour | createSignedUrl with an image transformation |
createSignedURL(path:expiresIn:transform:) with an ImageTransformation |
Storage caching |
| Replace photo, Move to another task, Duplicate to another task, Delete photo | update, move with an update of the row, copy with an insert, delete; all online only |
update(_:data:options:), move(from:to:) with an update of the row, copy(from:to:) with an insert, remove(paths:) |
Storage caching |
| A photo waiting to upload: its file on the device, a line saying the bucket's actions wait for the upload, Share, and Remove, with Retry once it failed, offline too | cachedFile answers the queued upload's file, and a refused one's is RejectedUpload.localPath; Retry and Remove as on Task detail |
No library call: the file and its record are the app's; Remove not while it uploads | Storage caching |
Photos¶
| What it shows | The calls | On iOS | Explained on |
|---|---|---|---|
| Every photo, newest first, a page at a time, each marked when it is on the device | selectAsFlow with order and range; Show more reads a longer page |
selectAsSequence with order and limit |
Reactive reads |
| The photos waiting to upload, among them with their marks | Their queued rows, marked from storage.pendingUploads() and storage.rejectedUploads() |
The app's pending-photo directory, merged with the page | Storage caching |
Sync¶
| Section | What it shows | The calls | On iOS | Explained on |
|---|---|---|---|---|
| Connection | The network, and Simulate offline | syncStatus.network; disableNetwork() and enableNetwork() |
The same | Replaying the queue |
| Settings | Prefer fresh data, and Live updates with where its channel stands | The list's read strategy; realtime { table(…) } in the plugin's configuration, realtimeStatus mapped onto the row's words, and enableRealtime() / disableRealtime() behind the switch |
Config.realtimeTables, realtimeStatus, and the same switch, called again around a sign-in |
Reactive reads, Applying Realtime events |
| Waiting changes | The count per table, one row per change ("Added “Buy milk”, 2 minutes ago") with Discard, when it last synced or why it stopped, and Sync now with every count of its report | pendingMutationCountFlow(table), pendingMutations(), discardPendingMutation(id), lastSyncedAt, lastSyncError, syncPendingMutations() and its SyncReport |
pendingMutationCountSequence(table:), pendingMutations(), discardPendingMutation(id:), then the same |
Writes and the offline queue, Replaying the queue |
| Refresh | Where the list's refresh stands | QuerySnapshot.refresh |
The same | Refresh lifecycle |
| Conflicting changes | Each change held because its task changed on the server too: which task, both values of each column both sides changed, when it was made and held, with Keep mine (off when the task is gone or the change too long to keep) and Keep theirs | versionColumn("tasks", "updated_at") and a conflictResolver in the configuration, conflictedMutations(), resolveConflictedMutation(id, KeepLocal) and (id, KeepServer), and the report's conflict counts |
Config.versionColumns and Config.conflictResolver, then the same |
Conflicts and merging |
| Refused changes | Each refused change, when it was made and refused, its rows and the server's answer, with Retry (off when it cannot be retried) and Dismiss | rejectedMutations(), retryRejectedMutation(id), dismissRejectedMutation(id) |
The same, with what the change did, and the server's details and hint | Failures and the rejected list |
| Server | "On the server: 7 of 12 done · 3 this week" | A count, and rpc("tasks_done_count", …) with typed and JSON parameters |
The same | One-shot reads, Coming from supabase-kt |
| Storage | Your folders in the bucket with their files, and Upload through a signed URL | list with a limit, an offset, a sort and a search; createSignedUploadUrl and uploadToSignedUrl |
Browse photo files: list(path:options:) with a StorageListFilter; the signed-URL upload is under Try it |
Storage caching |
| Try it | Queue an invalid title, Add five sample tasks, Import the starter list, Delete done tasks offline, A quote in an in list, Count open tasks on the server, Make a conflict; each says what it called and what happened | insert of a JSON body, insert of a list, upsert with onConflict and ignoreDuplicates, a grouped delete refused offline with MutationNotQueueableException, a read refused with IllegalArgumentException, a count with filter(column, operator, value) |
Count tasks with notes (filter("notes", operator: "not.is", value: "null")), Delete last week's done tasks (two conditions on one column, queued offline) and Upload through a signed URL in place of the count, the grouped delete and the quoted in value; Make a conflict plays the second writer itself in demo mode |
Writes and the offline queue, Coming from supabase-kt |
| Local data | Clear local cache, and Start over | clearLocalData(), which drops the photos waiting to upload too; Start over discards the waiting photo uploads (discardPendingMutation waits for one on the wire), clears, deletes the user's files, one that landed meanwhile too, and rows OnlineOnly, then signs in as a new user |
Clear local cache the same; Start over waits for a photo upload in progress, discards the user's waiting changes, deletes their files and rows .onlineOnly, turns the network off, signs out, clears the device and then the pending photos, signs in anew and turns the network back on |
Signing out and switching users |
Coming back to the app sends what waits: the app calls syncPendingMutations() as it comes to the
foreground (Replaying the queue).
Ten minutes with the app¶
Online basics¶
- Open the app. It signs in anonymously and shows an empty list.
- Add a task with New task: the app says it was saved, with the time the server stored it
(the row's
updated_at, which the server sets;created_atis the time the device made it). Open it, add some notes and tick it done. - In the dashboard, open the Table Editor and the
taskstable: the row is there, with your anonymous user's id inuser_idand the id the app made on the device inid.
Each change was sent at once, because nothing waited ahead of it.
Live updates¶
With Live updates on (the Sync tab's Settings), change a task's title in the Table Editor. The app shows the new title within a second or two: Realtime sent the row, and the library applied it to the list it keeps on the device, as the table is named in the app's configuration.
Go offline¶
On the Sync tab, switch on Simulate offline. It turns the library's network access off, as airplane mode would, for this app only and until you switch it back or the app restarts. The banner and the subtitle say the app is offline, and Sync now is switched off.
Write while offline¶
Add a task, clear another's notes, tick one done and delete one. Each change shows at once, with a cloud mark on the rows whose change has not reached the server; the banner and the Sync tab's badge count the changes waiting, and the Sync tab lists each one. Pull to refresh: the caption under the title says the list is from this device, and how old it is.
Open a task you have never opened before: it opens offline too, because the app reads its list once and finds the task in it. Tap a chip or search for a word you never asked for online: there is nothing saved for it, and the app says so.
Come back online¶
Switch Simulate offline off. The library sends the waiting changes by itself, in the order you made them, and the count drops to Nothing waiting.
Check the dashboard¶
Refresh the tasks table in the Table Editor: the new task is there, the notes are cleared, the
task is done, and the deleted one is gone. Each row's updated_at is the server's time, set when
the change arrived.
Cold start offline¶
Simulate offline does not survive a restart, so use the device's airplane mode for this one.
- Turn on airplane mode and close the app completely.
- Open it again. The list is there, read from the device; the session is the same anonymous user, restored from the device too.
- Add a task, then close the app again. The change is kept on the device.
- Turn airplane mode off and open the app: the task is sent.
Photos¶
- Online, open a task and choose Add photo. The photo shows at once, marked while it uploads, and the mark goes once the upload is done.
- Open the photo, then Details: the file is in the bucket and on this device. Try Share link and Move to another task.
- Switch on Simulate offline, open New task, give it a title and Add photo (pick two), then save. Open the task: its photos show at once, from the device, each marked "Waiting to upload". The Photos tab has them too. Open one: the viewer shows it, and says why Details, Share link, Replace, Move and Duplicate need the photo on the server.
- In the dashboard, the
task_photostable and the bucket's folder for the task have nothing new: on Android the photos wait in the library's queue, behind the queued task; on iOS in the app's own queue. - Switch Simulate offline off. The queued task is sent and the photos upload one at a time;
each photo's row follows its file, behind its task's, and its mark goes.
Refresh
task_photosand the bucket: both photos are there. - Every other change to a photo (Replace, Move, Duplicate, Delete) still needs the network: offline they are switched off, and the photos already on the device still show.
A refused write¶
On the Sync tab, under Try it, choose Queue an invalid title while offline. It adds a task with a blank title, which the schema refuses, and the change waits like any other. Come back online: the server refuses it (HTTP 400, Postgres code 23514), and it moves to Refused changes with the server's answer and the Tasks tab says so. Retry sends it again; Dismiss removes it.
Online, the same item's write is refused as soon as it is sent, and the line under it says why: a write sent at once that the server refuses is thrown to the app, not listed.
Writes the queue cannot hold¶
Still under Try it, with Simulate offline on, choose Delete done tasks offline. A delete filtered by a group of conditions cannot wait in the queue, so the library refuses it at once and says which kind of write it was; nothing is queued. A quote in an in list is a read the library refuses online and offline alike, before anything is sent: the server would read the escaped quote as part of the title. On iOS the item is Delete last week's done tasks, whose two conditions on one column are top-level filters the queue records, so offline that delete waits in the queue instead; there is no A quote in an in list.
Try a conflict¶
The samples name updated_at, which the schema's trigger moves on every change, as the version
column of both tables, so a change queued offline is sent only while the task still has the
version the app saw. Two devices are two anonymous users, so play the second writer from the Table
Editor. Switch Live updates off first, so the app shows only what it reads. Make a conflict,
under Try it, says the same steps; on iOS in demo mode it plays them itself, with the stand-in
server as the second writer.
- Go offline in the app and tick a task done.
- In the Table Editor, change the same task's title.
- Come back online. The queued update finds the task moved, reads it again, sees that only the
title changed there and that the update sets only
done, and sends it again at the new version: both changes stand, and nothing asks you anything. - Now go offline, change a task's title in the app, change the same title in the Table Editor, and come back online. Both sides changed the title, so the app's resolver holds the change, and it waits under Conflicting changes on the Sync tab, with both titles.
- Tap Keep mine: the app's title is sent against the task as the Table Editor left it, and wins. Keep theirs drops it, and the Table Editor's title stays on both.
- Delete a task in the Table Editor after changing it offline in the app: when the app comes back, the change is dropped, and the task leaves the list; nothing is recreated.
Conflicts and merging walks through what the library sent at each step.
Start again¶
Under Local data on the Sync tab:
- Clear local cache deletes what the device holds, the queue and the photos waiting to upload included, then reads both lists again from your project.
- Start over deletes this user's photos, photo rows and tasks from your project, clears the device and the photos waiting to upload, and signs in as a new anonymous user. It needs the network.