Inspiration
Almost every AI app built today has the same hidden dependency: a working internet connection. Take away the signal and the "intelligence" disappears, because the model was never on your device — it was in someone's data centre.
That dependency is invisible until the exact moment it matters.
A woman walking back alone through an unfamiliar part of a city. A hiker on a trail that stopped looking familiar an hour ago. Someone travelling through a region where coverage simply doesn't reach. These are the moments a person most wants a second opinion, a way to think a situation through, or just to know which direction their car is in — and they are precisely the moments the cloud cannot help.
I wanted to find out whether a genuinely useful AI assistant could live entirely on a phone, with the radios switched off. Not a cached FAQ. Not a degraded fallback mode. A real language model, doing real inference, on the device in your hand.
What it does
Offline Companion is an iPhone app that keeps working when nothing else does. Put the phone in airplane mode and it still:
- Answers questions. Meta Llama 3.2 1B Instruct runs on the phone's own silicon. In testing on an iPhone 13, a practical question — "Can we eat hibiscus plant leaves?" — came back with a careful, useful answer in 4.6 seconds, with no network of any kind.
- Listens and speaks. Apple's on-device speech recognition turns what you say into editable text that you review before sending; any answer can be read back aloud. Useful when you're walking, and essential for accessibility.
- Describes photos. An experimental second model, SmolVLM-500M, answers questions about a photo you choose — also entirely on the device.
- Shows you where you are. A full OpenStreetMap street map of central Auburn, Alabama is bundled into the app and rendered by MapLibre. No tiles to fetch, no map API key, nothing to download.
- Remembers places and points you back. Save your car, your camp or a trailhead by name, and a compass arrow gives you the bearing and straight-line distance back to it.
- Routes you on foot, offline. The app computes a real walking route over stored OpenStreetMap paths — a 225 m route in the demo — using actual OSM node connectivity, not a straight line drawn on a map.
- Connects you to one trusted person nearby. Two phones pair by scanning a private QR code and explicitly accepting the invitation. After that, GPS readings move directly between the two phones over AES-GCM encrypted Bluetooth, with no internet and no server in the middle. Every position shows its own timestamp and accuracy, because being connected is not the same as knowing where someone is right now.
There is no account, no login, no email, no password and no backend. The app asks your first name once, stores it on the phone, and that's the entire sign-up.
How AI is used
This is the heart of the project, so it's worth being precise.
Text — Meta Llama 3.2 1B Instruct (GGUF, Q4_K_M)
The weights run locally through llama.cpp, reached from Swift via the LlamaSwift package. All inference state lives inside a dedicated Swift actor, off the UI thread. On device, every transformer layer is offloaded to the GPU through Metal (n_gpu_layers = -1); the simulator falls back to CPU. Context is 2048 tokens, batch 128, greedy sampling for deterministic output, and answers are capped at 192 tokens so generation stays responsive on a 4-year-old phone.
A 1-billion-parameter model at 4-bit quantisation was chosen deliberately: it is roughly 808 MB on disk and fits in an iPhone 13's memory budget alongside a MapLibre map, Core Bluetooth and Core Location all running at once. This was practical selection under hard device constraints, not a benchmark sweep.
Vision — SmolVLM-500M-Instruct (GGUF, Q8_0) + its mmproj vision projector Loaded through llama.cpp's multimodal path. Photos are downscaled on-device to 768 px on the longest side and re-encoded before they ever reach the model. This is a Hugging Face model, not a Meta model, and the app labels it as such in its own UI.
Speech — Apple's on-device frameworks
SFSpeechRecognizer with requiresOnDeviceRecognition = true, so audio is never sent to a transcription service — there is deliberately no cloud fallback. AVSpeechSynthesizer handles read-aloud.
Responsible AI, built into the architecture rather than bolted on
Running the model locally isn't just a performance choice — it's the privacy model. Your questions and your photos never leave the phone, because there is nowhere for them to go. There is no inference endpoint anywhere in the source code, no API key, and no telemetry.
The system prompt constrains the model hard. It is told it has no internet, no current news, no location-reading tool and no messaging tools; that it cannot operate the map screens; that it must say when it does not know; and that it must never invent observations, alerts or rescue activity. It can draft a message for you to review, but it cannot send anything and it never claims to have.
The UI reinforces this everywhere: every answer is labelled with which model produced it, each question is explicitly independent (the context is cleared before every single question — there is no hidden conversational memory), the photo mode is labelled experimental and error-prone, and a persistent line reads "AI can make mistakes. Each question is independent. No SOS messages are sent."
Most importantly: the app never pretends to be a safety service. It has no satellite link, no SOS transmission and no connection to emergency dispatch, and it says so plainly in the app, in the README and in the demo video. For a tool aimed at people in vulnerable moments, overpromising would be the single most harmful thing it could do.
How I built it
Native SwiftUI, iOS 17+, 3,165 lines of Swift across 13 files, and no backend at all.
- Model management — downloads are verified before installation against both an expected byte size and a pinned SHA-256, streamed in 4 MB chunks. A truncated or tampered file is rejected rather than loaded. Weights land in Application Support and are excluded from iCloud backup.
- Offline map data — I processed the Geofabrik Alabama OpenStreetMap extract (151 MB) down to a 5.6 MB bundled dataset covering central Auburn: 11,888 features, 83,161 coordinate points, with original OSM node IDs and way IDs preserved so that road connectivity survives. Downloaded regions are stored LZFSE-compressed.
- Rendering — MapLibre Native 7.0.0, with the style JSON generated at runtime from local GeoJSON sources and Latin glyphs bundled in the app. There is no network basemap fallback anywhere.
- Offline routing — a shortest-path search over the OSM graph using shared node IDs, so two roads that merely cross on screen are not treated as connected. It honours pedestrian access tags and one-way foot restrictions, snaps start and destination up to 150 m to the nearest mapped node, and refuses to produce a route when coverage is missing or disconnected rather than drawing a misleading straight line.
- Pairing protocol — each phone generates a 256-bit random secret, encodes it in its QR, and derives its own BLE service UUID from SHA-256 of that key. Every control and location message is AES-GCM authenticated under it. Acceptance binds the pairing to a specific request UUID, so a stray or replayed message can't create a connection. Pairings persist in the Keychain as this-device-only, after-first-unlock.
Challenges I ran into
Fitting a language model into a phone's memory budget. The hard part wasn't loading the model — it was loading it while MapLibre, Core Bluetooth and Core Location were all live. Only one model is held in memory at a time, and switching between text and photo mode fully unloads the previous one before loading the next.
Keeping llama.cpp off the main thread. C interop plus SwiftUI is an easy way to produce a frozen UI. Isolating every pointer inside a Swift actor and making every long operation cancellable took real iteration.
Routing that tells the truth. My first version connected roads wherever their lines crossed geometrically. That produces routes through walls. Rewriting it to use shared OSM node IDs was the single biggest correctness improvement in the project — and teaching it to refuse rather than guess was the second.
Bluetooth pairing that actually completes. Getting two phones through discovery, an authenticated invitation, an explicit Accept and an acknowledgement — and then surviving reconnection — needed a retry loop, per-request UUID binding, and progress labels on both screens so a discovery failure is distinguishable from a delivery failure.
Public map servers that don't answer. Downloading extra regions depends on public Overpass endpoints, which failed repeatedly during testing. Rather than ship a feature that quietly breaks, I bundled the Auburn dataset directly into the app so the core experience never depends on a server that might not be there.
Accomplishments I'm proud of
- It genuinely works with the radios off. Not a demo trick — airplane mode is visible in the status bar throughout the demo video, including a cold app launch that proves the model loads from local storage.
- A real answer in 4.6 seconds on a 4-year-old phone, generated on the device.
- A walking route computed offline over real OSM data, with honest handling of the gaps it can't route.
- Privacy that is structural, not a policy page. There is no server to trust, because there isn't one.
- Documentation and a demo that are honest about limits. Every capability claim in the README and the video was checked against the source before it was written.
What I learned
That the interesting constraint in AI right now isn't model quality — it's where the model runs. A 1B model you actually have beats a 400B model you can't reach. Quantisation, memory budgeting and prompt discipline matter far more on-device than they do behind an API.
I also learned how much of an "AI app" isn't AI. Most of the engineering here went into map data processing, BLE protocol design, graph search and permission handling — the model is one component in a system that has to be trustworthy end to end.
And I learned that for a tool people might lean on in a bad moment, the most important feature is knowing what to refuse to claim.
What's next
- Bundling more regions, and a proper hosted map pipeline instead of public Overpass endpoints.
- Characterising background Bluetooth delivery properly under iOS's scheduling.
- Larger quantised models on newer devices, with automatic selection based on available memory.
- More than one trusted contact, and a pairing flow that survives longer gaps.
- Accessibility work: VoiceOver passes, larger text, and more languages for on-device speech.
Honest status
This is a working prototype, tested on an iPhone 13 with a second iPhone for pairing. Everything in the demo video is real, unaltered footage recorded in airplane mode. Sustained background location delivery while the phone is locked still needs proper characterisation, and downloading map regions beyond the bundled Auburn dataset depends on public servers that have been unreliable. It is not an emergency service, and it does not claim to keep anyone safe.
Built With
- aes-gcm
- avfoundation
- core-bluetooth
- core-location
- cryptokit
- gguf
- hugging-face
- ios
- keychain
- llama-3.2
- llama.cpp
- lzfse
- maplibre
- meta-llama
- metal
- natural-earth
- on-device-ai
- openstreetmap
- quantization
- smolvlm
- speech-framework
- swift
- swift-package-manager
- swiftui
- xcode