Files
quicproquo/sdks/swift/README.md
Christian Nennemann f57dda3f36 feat(sdk): add Swift and Kotlin mobile client foundations with push token proto
Swift SDK: Swift Package wrapping libquicproquo_ffi with QpqClient class
(connect, login, send, receive, disconnect) for iOS 15+ / macOS 13+.

Kotlin SDK: JNI bridge to libquicproquo_ffi with QpqClient class for
Android (aarch64, armv7) and JVM, Gradle build configuration.

Adds RegisterPushToken RPC (method ID 710) to device.proto for
APNs/FCM/WebPush device push token registration.
2026-03-04 20:58:23 +01:00

105 lines
2.3 KiB
Markdown

# QuicProQuo Swift SDK
Swift wrapper over `libquicproquo_ffi` for iOS and macOS.
## Prerequisites
- Xcode 15+ / Swift 5.9+
- iOS 15+ or macOS 13+
- `libquicproquo_ffi` built for the target architecture
## Building the Native Library
```sh
# iOS (device)
cargo build --release -p quicproquo-ffi --target aarch64-apple-ios
# iOS Simulator (Apple Silicon)
cargo build --release -p quicproquo-ffi --target aarch64-apple-ios-sim
# macOS
cargo build --release -p quicproquo-ffi --target aarch64-apple-darwin
```
## Installation
### Swift Package Manager
Add to your `Package.swift`:
```swift
dependencies: [
.package(path: "sdks/swift"),
]
```
Or add the library search path to your Xcode project:
```
LIBRARY_SEARCH_PATHS = $(PROJECT_DIR)/../target/release
OTHER_LDFLAGS = -lquicproquo_ffi
```
## Usage
```swift
import QuicProQuo
let client = try QpqClient(
server: "127.0.0.1:5001",
caCertPath: Bundle.main.path(forResource: "ca", ofType: "pem")!
)
try client.login(username: "alice", password: "secret")
try client.send(to: "bob", message: "hello".data(using: .utf8)!)
let messages = try client.receive(timeoutMs: 5000)
for msg in messages {
print("Received: \(msg)")
}
client.disconnect()
```
## API
| Method | Description |
|---|---|
| `QpqClient(server:caCertPath:serverName:)` | Connect to server |
| `client.login(username:password:)` | OPAQUE authentication |
| `client.send(to:message:)` | Send message by username |
| `client.receive(timeoutMs:)` | Receive pending messages |
| `client.disconnect()` | Disconnect |
| `client.isConnected` | Connection status |
## Error Handling
All errors are thrown as `QpqError`:
```swift
do {
try client.login(username: "alice", password: "wrong")
} catch QpqError.authFailed(let msg) {
print("Authentication failed: \(msg)")
} catch QpqError.connectionFailed(let msg) {
print("Connection failed: \(msg)")
}
```
## Structure
- `Sources/CQuicProQuo/` -- C module map and FFI header
- `Sources/QuicProQuo/QpqClient.swift` -- High-level Swift client
- `Sources/QuicProQuo/QpqError.swift` -- Error types
## Cross-Compilation
For iOS devices, add the Rust target and build:
```sh
rustup target add aarch64-apple-ios
cargo build --release -p quicproquo-ffi --target aarch64-apple-ios
```
Copy the library to your Xcode project's framework search path.