View as Markdown

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()
}
ParameterTypeWhat it is
baseURLURLYour Provenance API's base URL
sourceTextConsentStepSourceThe request: .captureEmbedToken(embedToken:publishableKey:) or .captureLink(token:)
transportTextConsentTransportOptional. The HTTP client; URLSessionTransport() by default
onError(TextConsentError) -> VoidOptional. A refusal or a network failure
onFinish(TextConsentStepOutcome) -> VoidCalled 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.

TextConsentStepOutcomeWhen
.agreedText me recorded the consent
.notNowNot now: nothing was sent and nothing is stored
.notOfferedThe 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
}
ParameterTypeWhat it is
baseURLURLYour Provenance API's base URL
publishableKeyStringA publishable key with no allowed origins: an app sends no Origin
embedTokenStringA token your backend minted with { "widget": "text_consent", "object_id": "<box_id>" }
phoneStringThe mobile number your screen collected: E.164, or ten US digits
onConsented(String) -> VoidOptional. The record's id after a tick
onWithdrawn(String) -> VoidOptional. The record's id after an untick
onError(TextConsentError) -> VoidOptional. A refusal or a network failure

Read the record from your backend with GET /v1/account/text_consents/{id} 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

ViewReadRecordUndo
TextConsentStep, embed tokenGET /v1/embed/capture_request ?surface=swiftPOST /v1/embed/text_consents { step: true, wording_version, surface }None: a consent is withdrawn by the person
TextConsentStep, capture linkGET /v1/attest/capture_links ?surface=swiftPOST /v1/public/text_consents { link_token, wording_version, surface }None
TextConsentViewGET /v1/embed/text_consents/form ?surface=swiftPOST /v1/embed/text_consents { phone, wording_version, surface }POST /v1/embed/text_consents/{id}/withdraw

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

FieldWhat it is
codeThe API's error code, such as plan_required or parameter_invalid, or network_error when nothing came back
messageA sentence you can show
statusThe HTTP status, or 0 with no answer

See also