Files
smoa/docs/ios/SAMPLES.md
T
defiQUG a2dc194a49 Monorepo: Gitea CI, docs, auth/sync, backend APIs, gitignore
- Add Gitea Actions workflow; point README to gitea.d-bis.org/Sankofa_Phoenix/SMOA
- Expand .gitignore for Spring H2 data, secrets, Kotlin .kotlin/, tooling
- Track docs/api/generated ReDoc bundle; refresh api docs README
- Android: network/auth/sync, UI shell, tests; backend credentials/integrity APIs
- Docs, scripts (generate-api-docs), modules and core updates

Made-with: Cursor
2026-03-23 20:19:24 -07:00

1.7 KiB

iOS samples (Keychain, API key, offline queue)

Use with docs/ios/README.md. These snippets are reference only (not a full Xcode project).

Store API key in Keychain

import Security

func saveApiKey(_ value: String, service: String = "com.smoa.api") throws {
    let data = Data(value.utf8)
    let query: [String: Any] = [
        kSecClass as String: kSecClassGenericPassword,
        kSecAttrService as String: service,
        kSecAttrAccount as String: "apiKey",
        kSecValueData as String: data
    ]
    SecItemDelete(query as CFDictionary)
    let status = SecItemAdd(query as CFDictionary, nil)
    guard status == errSecSuccess else { throw NSError(domain: NSOSStatusErrorDomain, code: Int(status)) }
}

func loadApiKey(service: String = "com.smoa.api") -> String? {
    let query: [String: Any] = [
        kSecClass as String: kSecClassGenericPassword,
        kSecAttrService as String: service,
        kSecAttrAccount as String: "apiKey",
        kSecReturnData as String: true
    ]
    var out: AnyObject?
    guard SecItemCopyMatching(query as CFDictionary, &out) == errSecSuccess,
          let data = out as? Data else { return nil }
    return String(data: data, encoding: .utf8)
}

Simple offline sync queue (UserDefaults + retry)

Persist operation JSON strings; on NWPathMonitor satisfied, POST to /api/v1/... with URLSession and remove on success.

Face ID / Touch ID

Wrap Keychain access with LAContext().evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, …) before reading sensitive items.

Certificate pinning

Use URLSessionDelegate urlSession(_:didReceive:completionHandler:) and compare SecTrust server pins to your SPKI hashes.