Manage Sudos
Create Sudos
To create a new Sudo:
do {
let sudoInput = SudoCreateInput(
title: "Mr.",
firstName: "John",
lastName: "Smith",
label: "Shopping",
notes: "Used for shopping.",
avatar: .fileUrl(avatarUrl)
)
let sudo = try await client.createSudo(input: sudoInput)
// Create successful
} catch {
// Handle error. An error may be thrown if the backend is unable
// to create the Sudo due to availability, security or entitlement issues or
// due to unrecoverable circumstances arising from programmatic error or
// configuration error. For example, if the keychain access entitlement
// is not set up correctly, the client is not signed in,
// or basic system resources are unavailable.
}
List Sudos
To list Sudos:
do {
let sudos = try await client.listSudos(cachePolicy: .remoteOnly)
// Download the avatar images.
for sudo in sudos {
if let avatarClaim = sudo.avatarClaim {
let data = try await client.getBlob(forClaim: avatarClaim, cachePolicy: .remoteOnly)
let image = UIImage(data: data)
}
}
} catch {
// Handle error. An error may be thrown if the backend is unable
// to list Sudos due to availability or for unrecoverable circumstances arising
// from programmatic error or configuration error. For example, if the keychain
// access entitlement is not set up correctly, the client is not signed in,
// or basic system resources are unavailable.
}
Modify Sudos
To update an existing Sudo:
let updateInput = SudoUpdateInput(
sudoId: sudoId,
version: version,
firstName: .newValue("David")
)
do {
let updatedSudo = try await client.updateSudo(input: updateInput)
// Update successful.
} catch {
// Handle error. An error may be thrown if the backend is unable to
// update Sudo due to availability or security issues or for unrecoverable
// circumstances arising from programmatic error or configuration error.
// For example, if the keychain access entitlement is not set up correctly,
// the client is not signed in, or basic system resources are unavailable.
}
Subscribe to Changes
To subscribe to a specific Sudo change notification:
class MySubscriber: SudoSubscriber {
func sudoChanged(changeType: SudoChangeType, sudo: Sudo) {
// Process new, updated or deleted Sudo.
}
func connectionStatusChanged(changeType: SudoChangeType, state: SubscriptionConnectionState) {
if state == .connected {
// The subscription for the provided change type is now connected hence the subscribers
// will start receiving Sudo changes.
} else if state == .disconnected {
// The subscription is disconnected and all subscribers for the provided
// change type were automatically unsubscribed. Subscribe again to establish a
// new connection or report the error.
}
}
}
let subscriber = MySubscriber()
do {
try await client.subscribe(id: "subscriber_id", changeTypes: [.create], subscriber: subscriber)
} catch {
// Handle error. An error might be thrown for unrecoverable circumstances arising
// from programmatic error or configuration error. For example, if the keychain
// access entitlement is not set up correctly, the client is not signed in,
// or basic system resources are unavailable.
}
To subscribe to Sudo change notification of all types:
class MySubscriber: SudoSubscriber {
func sudoChanged(changeType: SudoChangeType, sudo: Sudo) {
// Process new, updated or deleted Sudo.
}
func connectionStatusChanged(changeType: SudoChangeType, state: SubscriptionConnectionState) {
if state == .connected {
// The subscription is now connected hence the subscribers
// will start receiving Sudo changes.
} else if state == .disconnected {
// The subscription is disconnected and all subscribers were
// automatically unsubscribed. Subscribe again to establish a
// new connection or report the error.
}
}
}
let subscriber = MySubscriber()
do {
try await client.subscribe(id: "subscriber_id", subscriber: subscriber)
} catch {
// Handle error. An error may be thrown for unrecoverable circumstances arising
// from programmatic error or configuration error. For example, if the keychain
// access entitlement is not set up correctly, the client is not signed in,
// or basic system resources are unavailable.
}
Delete Sudos
To delete an existing Sudo:
let input = SudoDeleteInput(sudoId: sudoId, version: version)
do {
try await client.deleteSudo(input: input)
// Delete successful.
} catch {
// Handle error. An error might be thrown if the backend is unable
// to delete the Sudo due to availability or security issues or for
// unrecoverable circumstances arising from programmatic error or
// configuration error. For example, if the keychain access entitlement is
// not set up correctly, the client is not signed in, or basic system
// resources are unavailable.
}
Get Ownership Proof
Many Sudo Platform services require the user to present a proof that they own a particular Sudo so that a provisioned resource can be associated with a Sudo. Sudo Profiles SDK provides an API to generate a cryptographic proof of Sudo ownership so it can be used in provisioning APIs of other SDKs such as Email SDK.
To obtain a Sudo ownership proof for provisioning a resource tied to a Sudo.
do {
let jwt = try await client.getOwnershipProof(sudo: sudo, audience: "<service_specific_audience>")
// Ownership proof obtained successfully.
} catch {
// Handle error. An error might be thrown if the backend is unable
// to delete the Sudo due to availability or security issues or for
// unrecoverable circumstances arising from programmatic error or
// configuration error. For example, if the keychain access entitlement is
// not set up correctly, the client is not signed in, or basic system
// resources are unavailable.
}
Resetting Client State
You can reset the internal state information maintained by SudoProfilesClient
by calling reset
API.
Resetting the client state will cause all persistent data to be lost including any cached Sudos and encryption keys. Unless you are intending to import the encryption keys from an external source, e.g. key backup, you should call generateEncryptionKey
API to create a new encryption key before using SudoProfileClient
again.
do {
try await client.reset()
} catch {
// Handle error. An error may be thrown for unrecoverable circumstances arising
// from programmatic error or configuration error. For example, basic system resources
// are not accessible.
}
Last updated