Consent Flow
Managing user opt-in for resource contribution.
Overview
TealeSDK requires explicit user consent before contributing any device resources to the network. Consent is persistent across app launches and can be revoked at any time. The SDK provides both programmatic consent management and a pre-built SwiftUI consent view.
Requirements
- Consent must be granted before
start()proceeds. Ifstart()is called without consent, the contributor moves towaitingForConsentstate and waits. - Users must be able to revoke consent at any time. Revoking consent immediately stops all contributions and disconnects from the network.
- Consent persists across launches. Once granted, the user does not need to re-consent on each launch.
ConsentManager
The SDK's internal ConsentManager handles persistence. You interact with it through TealeContributor:
// Check current consent status
if contributor.hasUserConsent {
print("User has consented")
}
// Grant consent (after showing your own UI or using ConsentPromptView)
contributor.grantConsent()
// Revoke consent
contributor.revokeConsent()
ConsentPromptView
The SDK provides a standard SwiftUI view that explains what resource contribution means and asks for permission.
import TealeSDK
struct MyView: View {
let contributor: TealeContributor
var body: some View {
if !contributor.hasUserConsent {
ConsentPromptView(contributor: contributor)
} else {
Text("Contributing to the Teale network")
}
}
}
The ConsentPromptView displays:
- What resources will be shared (RAM, CPU/GPU compute)
- Impact on device performance and battery
- How the user can revoke consent later
- An "Allow" button that calls
grantConsent() - A "Not Now" button that dismisses the prompt
Custom Consent UI
If you prefer your own consent UI, call grantConsent() programmatically after the user agrees:
Button("I agree to contribute resources") {
contributor.grantConsent()
Task {
try await contributor.start()
}
}
Ensure your custom UI clearly discloses:
- That device resources (RAM, compute) will be used for AI inference
- That contribution can be stopped at any time
- That the device may use more power during contribution
- How to access settings to revoke consent later
Consent State Flow
grantConsent() revokeConsent()
| |
v v
[waitingForConsent] --> [connecting] --> [idle]
|
v
[contributing]
- Before consent: state is
idleorwaitingForConsent - After
grantConsent()+start(): state moves toconnecting, thencontributing - After
revokeConsent(): state returns toidle, network disconnected, consent flag cleared