Files
hapi/ios/Packages/HapiKit/Sources/HapiClient/Endpoints/LiveActivityEndpoints.swift
T
b81c6be39b feat(ios): add lock-screen Live Activities for running sessions
Hub:
- add encrypted Live Activity token registry, registration API, and
  update/end pushes over direct APNs
- enable only for HAPI_IOS_PUSH=apns; relay reports remote:false
- keep content-state encrypted with the per-install push key and a
  domain-separated AAD

iOS:
- add ActivityKit coordinator, HapiWidgets extension, lock-screen and
  Dynamic Island UI, encrypted content-state, deep links, and settings toggle
- cap concurrent activities and reconcile across hub switches

Docs/tests:
- native contract, privacy, READMEs, localization catalogs
- cross-language cipher fixture and hub/iOS unit tests

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>
Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-06 19:18:09 +08:00

72 lines
2.3 KiB
Swift

import Foundation
/// Response of `POST /api/live-activities/register`.
///
/// `remote` is false when the hub is not in direct-APNs mode: the app can
/// still show a local activity while it runs, but no remote updates will
/// arrive, so it should end on background / use a short stale date.
public struct LiveActivityRegistrationResponse: Decodable, Equatable, Sendable {
public let ok: Bool
public let remote: Bool
public init(ok: Bool, remote: Bool) {
self.ok = ok
self.remote = remote
}
}
extension APIClient {
/// `POST /api/live-activities/register` — upserts the per-activity APNs
/// token for a session. The hub encrypts future content-state pushes
/// with `pushKey` (the same per-install E2E key used by alert pushes).
public func registerLiveActivityToken(
token: String,
deviceId: String,
sessionId: String,
pushKey: String
) async throws -> LiveActivityRegistrationResponse {
struct RegisterRequest: Encodable {
let token: String
let deviceId: String
let sessionId: String
let pushKey: String
}
return try await request(
.post,
"/api/live-activities/register",
body: RegisterRequest(
token: token,
deviceId: deviceId,
sessionId: sessionId,
pushKey: pushKey
)
)
}
/// `DELETE /api/live-activities/register` by activity token.
public func unregisterLiveActivityToken(token: String) async throws {
struct UnregisterRequest: Encodable {
let token: String
}
try await requestVoid(
.delete,
"/api/live-activities/register",
body: UnregisterRequest(token: token)
)
}
/// `DELETE /api/live-activities/register` by device/session (used when
/// the activity ended before its token arrived).
public func unregisterLiveActivityTokens(deviceId: String, sessionId: String) async throws {
struct UnregisterRequest: Encodable {
let deviceId: String
let sessionId: String
}
try await requestVoid(
.delete,
"/api/live-activities/register",
body: UnregisterRequest(deviceId: deviceId, sessionId: sessionId)
)
}
}