- Swift 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| assets | ||
| SkyChat | ||
| SkyChat.xcodeproj | ||
| .gitignore | ||
| README.md | ||
SkyChat
Chat between iPhones and iPads over Bluetooth LE, with no Wi-Fi, cellular or shared network. It's built for flights: turn on flight mode, switch Bluetooth back on, and talk to the person a few seats away.
Status
Step 2: chat. Devices running SkyChat find each other and open an L2CAP channel. You get a Messages-style chat with bubbles, a typing indicator, Delivered/Read receipts, and history stored with SwiftData. Messages written while the other device is out of range are sent when it's back. A Bluetooth log (under Settings) shows what's happening on each side.
| Step | What | Status |
|---|---|---|
| 1 | Discovery, role selection, handshake, hello over GATT | ✅ |
| 2 | L2CAP channel + length-prefixed framing, chat UI, SwiftData history, iPad | ✅ |
| 3 | Acks, outbox/retry, auto-reconnect polish (basic receipts + resend done in 2) | ⏳ |
| 4 | QR pairing + end-to-end encryption (CryptoKit X25519 / ChaChaPoly) | ⏳ |
| 5 | Background modes, state restoration, local notifications | ⏳ |
| 6 | Optional: photos, Wi-Fi peer-to-peer upgrade, mesh relay | ⏳ |
Building
Requirements: Xcode 16 or newer and two physical iPhones or iPads on iOS 17 or later. The Simulator has no Bluetooth.
- Open
SkyChat.xcodeproj. - Select the SkyChat target → Signing & Capabilities, pick your team.
If
tech.bendiksen.skychatis taken for your team, change the bundle ID. - Run on both devices and allow Bluetooth when prompted.
- Optionally tap the person icon to set a display name.
- Within a few seconds each device lists the other, with a green dot on its avatar. Tap it and start typing.
On iPad the conversation list and the chat sit side by side. On iPhone they collapse into one navigation stack, as in Messages.
If you ran step 1 before, reinstall on both devices: the wire protocol is now v2.
The project uses folder-synced groups. Any file you add under SkyChat/
is part of the app target automatically, with no project-file edits needed.
Testing in flight mode
Turn on flight mode, then open Control Center and tap Bluetooth so it's on again. iOS remembers this, so next time flight mode leaves Bluetooth on. If Bluetooth is off, SkyChat shows a banner explaining this.
How it works
Every phone runs both Bluetooth LE roles at once:
- Peripheral: advertises the SkyChat service and serves its characteristics.
- Central: scans for that service and connects to the phones it finds.
Two phones would otherwise connect to each other twice. Instead, each phone has a persistent random SkyChat ID, and the phone whose ID sorts lower keeps its outgoing connection while the other backs off. Both phones apply the same rule, so each pair ends up with exactly one link.
GATT layout
SkyChat service 8E4B1F2A-6C3D-4E7A-9B10-5D2F7C8A0001
├── identity …0002 read {"v":2,"id":"…","name":"…","psm":193}
├── inbox …0003 write WireMessage JSON, central → peripheral
└── outbox …0004 notify WireMessage JSON, peripheral → central
L2CAP channel (PSM picked by iOS)
[4-byte big-endian length][WireMessage JSON] both directions
Link setup (central side)
- Discover the service, connect, discover its characteristics.
- Read
identity. If our ID sorts higher, disconnect and let the other phone connect to us. - Subscribe to
outbox. - Write a
handshake(our ID and name) toinbox. - The peripheral answers with its own
handshake, carrying its L2CAP PSM. - Open an L2CAP channel to that PSM. From then on every message uses the channel. If it can't be opened, or closes, messages fall back to GATT.
If a phone goes out of range, the central re-issues connect. iOS connection
requests never time out, so the link comes back by itself when the phones are close again.
Messages
WireMessage is JSON with one-letter keys (k kind, i id, f from, n name,
t text, s sent-at, p PSM, r referenced ids, a typing active). Kinds:
| Kind | Meaning |
|---|---|
handshake |
ID, name and (from the peripheral) the L2CAP PSM |
chat |
A message. Its i is the same on both devices |
delivered / read |
Receipts for the chat ids in r |
typing |
Started (a: true) or stopped typing. Expires after 6 s without a refresh |
Over GATT each message must fit in one write (~512 B) or notification (~180 B). Over L2CAP frames can be up to 1 MiB.
Delivery
Messages are saved before they're sent. Whenever a link to a peer comes up or
improves (L2CAP opens), everything still pending or sent (no receipt yet)
goes out again, oldest first. The receiver drops duplicates by id and repeats its
receipts, so a lost receipt heals itself on the next resend.
Layout
SkyChat/
├── App/SkyChatApp.swift App entry, owns transport, chat store, SwiftData container
├── Bluetooth/
│ ├── BLEConstants.swift UUIDs and the role rule
│ ├── BluetoothTransport.swift Central + peripheral, link setup, send/receive
│ └── L2CAPConnection.swift Length-prefixed framing over an L2CAP channel
├── Chat/ChatStore.swift Transport ↔ history: send, resend, receipts, typing
├── Model/
│ ├── ChatModels.swift SwiftData Conversation + ChatMessage
│ ├── LocalIdentity.swift Persistent SkyChat ID + display name
│ ├── Peer.swift Nearby device and log entry models
│ └── WireMessage.swift Wire format + codec
└── Views/ SwiftUI screens (list, chat, bubbles, composer)