Texts and reminders · Reference
Text consent for Swift
ProvenanceTextConsent puts the consent to text step and box in your own iOS app, as two SwiftUI views: TextConsentStep before your request screen and TextConsentView on your sign-up or intake screen. Each records with surface: "swift". Both need iOS 16 or macOS 13, and Foundation and SwiftUI only.
This package isn't on the Swift Package Index yet. Until then, every request in these docs runs over HTTP against the sandbox.
With access to the private Provenance repository, which your Provenance contact grants, install from it:
git clone https://github.com/michaelnbane-jpg/provenance.git provenance
// Package.swift: the package, then the product in your target
.package(path: "provenance/swift/provenance-text-consent")
.product(name: "ProvenanceTextConsent", package: "provenance-text-consent")TextConsentStep
The opt-in step a company's app shows before its own request screen, under Provenance asks. It reads the request, shows Texts from with your company's name and the masked phone, Provenance's wording with Terms · Privacy, Not now and Text me, Next with the request, and the Provenance mark.
import ProvenanceTextConsent
TextConsentStep(
baseURL: apiURL,
source: .captureEmbedToken(embedToken: captureToken, publishableKey: publishableKey)
) { outcome in
showRequestScreen()
}
| Parameter | Type | What it is |
|---|---|---|
baseURL | URL | Your Provenance API's base URL |
source | TextConsentStepSource | The request: . or . |
transport | TextConsentTransport | Optional. The HTTP client; URLSessionTransport() by default |
onError | (TextConsentError) -> Void | Optional. A refusal or a network failure |
onFinish | (TextConsentStepOutcome) -> Void | Called once when the step ends; show your request screen then |
Mint the embed token on your backend with { "widget": "capture", "object_id": "capr_…" }, as for the capture widget. The capture link's token is the part after /capture/ in the request's link.
TextConsentStepOutcome | When |
|---|---|
. | Text me recorded the consent |
. | Not now: nothing was sent and nothing is stored |
. | The request offers no step, or it couldn't be read: the view draws nothing and finishes at once |
The step is offered only when your mode is Provenance asks, you're on the Pro plan or above, the request carries a phone with text in its channels, and that phone has no consent for you and no stop. A refused Text me stays on the step with the reason under the wording.
TextConsentView
The consent box for your own form, in either mode. One box, unticked on every load, with the wording beside it, Terms · Privacy and the Provenance mark. Ticking it with a valid phone records a box consent; unticking withdraws it. On the Free plan it draws nothing.
TextConsentView(
baseURL: apiURL,
publishableKey: publishableKey,
embedToken: textConsentToken,
phone: mobile
) { consentId in
self.consentId = consentId
}
| Parameter | Type | What it is |
|---|---|---|
baseURL | URL | Your Provenance API's base URL |
publishableKey | String | A publishable key with no allowed origins: an app sends no Origin |
embedToken | String | A token your backend minted with { "widget": "text_ |
phone | String | The mobile number your screen collected: E.164, or ten US digits |
onConsented | (String) -> Void | Optional. The record's id after a tick |
onWithdrawn | (String) -> Void | Optional. The record's id after an untick |
onError | (TextConsentError) -> Void | Optional. A refusal or a network failure |
Read the record from your backend with GET / before you rely on it. It shows as Your app in Agreed to texts, with no form_origin.
Neither view takes a colour, font or checked argument: the wording, the box and the mark can't be restyled or pre-ticked. Both follow the system's light or dark appearance.
The calls they make
| View | Read | Record | Undo |
|---|---|---|---|
TextConsentStep, embed token | GET / ?surface=swift | POST / { step: true, wording_ | None: a consent is withdrawn by the person |
TextConsentStep, capture link | GET / ?surface=swift | POST / { link_ | None |
TextConsentView | GET / ?surface=swift | POST / { phone, wording_ | POST / |
The step never sends a phone: the token decides your account, the request and its phone. Every call sends User-Agent: provenance-swift/1.0.0 (text-consent). TextConsentClient makes the same calls without a view, and TextConsentStepModel and TextConsentBoxModel hold the views' state for your own layout or tests.
TextConsentError
| Field | What it is |
|---|---|
code | The API's error code, such as plan_ or parameter_, or network_ when nothing came back |
message | A sentence you can show |
status | The HTTP status, or 0 with no answer |
See also
- Get consent to text: the modes, the step, the box and the records
- Text consent for Kotlin: the same step and box in Jetpack Compose
- Embeds: publishable keys and embed tokens