Repository navigation
Mobile iOS stack
This page documents the reusable native iOS stack for apps that talk to Pair APIs. Its goal is to avoid rebuilding login, session handling, networking, and image caching differently in every project.
The Android counterpart is Mobile Android stack.
Pair provides:
- stable API contracts for login, registration,
/auth/me, and logout - Bearer tokens stored server-side in
api_tokens - mobile
remember_meenabled by default - mobile sessions separated from cookies, PHP sessions, and web remember-me records
- the Swift package
PairMobileKitinmobile/ios/PairMobileKit
Each app provides:
- domain-specific models, such as municipality, venue, customer, or tenant
- native routing and UI
- city, tenant, or default-context management
- application endpoints beyond authentication
The package is installable through Swift Package Manager from:
mobile/ios/PairMobileKit
Main components:
-
PairURLSessionTransport:URLSessionwith HTTP cache, conservative timeouts, and cookies disabled -
PairAPIClient: JSON client with Bearer auth,dataenvelopes, and401invalidation -
PairAuthService: login and registration withremember_me=trueforced and hidden from users -
PairJSONValue: nested JSON extra payloads without custom request types for small project fields -
PairKeychainStore: Codable Keychain store using an attribute that can migrate to a new phone -
PairSessionBootstrapper: startup restore for valid, revoked, and offline sessions -
PairRemoteImageCacheandPairCachedRemoteImage: cookie-free memory and disk image cache
Auth endpoints must use JSON and respond with a data envelope.
Login:
POST /api/v1/auth/login{
"email": "mario@example.test",
"password": "password",
"remember_me": true
}Registration:
POST /api/v1/auth/register{
"name": "Mario Rossi",
"email": "mario@example.test",
"password": "password",
"privacy_accepted": true,
"remember_me": true
}Response:
{
"data": {
"user": {
"id": 1,
"email": "mario@example.test",
"name": "Mario Rossi"
},
"token": "plain-token-only-once"
}
}The plain token is shown only in the login or registration response. The backend stores only the hash.
Apps store the session snapshot in Keychain with kSecAttrAccessibleAfterFirstUnlock. This allows the token to be included in backup and device-transfer flows supported by the system.
Apps that previously used a ThisDeviceOnly attribute can migrate by reading the snapshot and writing it again through PairKeychainStore.
Startup validation must call /auth/me:
- if it returns
200, the snapshot is refreshed - if it returns
401, Keychain is cleared and the user returns to login - if the network is unavailable, the app can open the saved context and retry later
Native apps must not use Pair cookies, sid, PHPSESSID, or user_remembers records. Mobile uses only Bearer tokens in api_tokens.
App login must not close or renew web login. Web login must not revoke mobile tokens except for account deactivation or explicit revocation.
import PairMobileKit
struct AppUser: Codable, Sendable {
let id: Int
let email: String
let name: String
}
let client = PairAPIClient(
apiBaseURL: URL(string: "https://example.test/api/v1")!
)
let auth = PairAuthService<AppUser>(client: client)
let session = try await auth.login(
email: "mario@example.test",
password: "password"
)
let store = PairKeychainStore<PairStoredAuthSession<AppUser, String>>(
service: "it.example.app"
)
await store.save(
PairStoredAuthSession(session: session, defaultContext: "crotone")
)- Use
PairURLSessionTransportor an equivalent cookie-free transport. - Do not expose a
remember metoggle in native apps. - Store the Bearer token only in Keychain.
- Validate the session at startup with
/auth/me. - Clear Keychain on logout, account deactivation, or
401. - Keep application models out of
PairMobileKit.
Every mobile stack change must pass:
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer swift test --package-path mobile/ios/PairMobileKitPair CI runs this command on macOS, separately from the PHP matrix on Ubuntu.
See also: Mobile Android stack, API, User, UserRemember, Upgrade-to-v4.
Maintained by Viames Marino — VM Ingegneria · Professional enquiries
Home · Setup · Configuration
Build with Pair 4
- Generator
- Controllers and responses
- Read models
- ActiveRecord and queries
- Forms and validation
- PairUI.js, PairMotion.js and HTML fragments
APIs and authentication
- API guide and CRUD
- Middleware and rate limits
- Users, sessions, and ACL
- Passkeys and social login
- Native mobile setup
Integrate and operate
- Integrations
- Runtime extensions and adapter keys
- Cache and cache stores
- Logs and observability
- PWA and push
- Packages and distribution
- Upgrade to v4