WebcomWrapper
public protocol WebcomWrapper
A type that wraps a callback-based type in order to enrich it with another API.
-
The type of the wrapped instance, which has a callback-based API.
Declaration
Swift
associatedtype Wrapped
-
The wrapped instance, which has a callback-based API.
Declaration
Swift
var wrapped: Wrapped { get }
-
authenticationToken
Extension methodThe authentication token.
Declaration
Swift
public var authenticationToken: String { get }
-
creationDate
Extension methodThe creation date of the user account.
Declaration
Swift
public var creationDate: Date { get }
-
displayName
Extension methodThe display name of the user, or
nil
when it is unavailable.Declaration
Swift
public var displayName: String? { get }
-
expirationDate
Extension methodThe expiration date of the authentication.
Declaration
Swift
public var expirationDate: Date { get }
-
provider
Extension methodThe provider of the current identity.
Declaration
Swift
public var provider: AuthenticationProvider { get }
-
providers
Extension methodThe providers used to get the different identities, starting from the current one.
By definition, the resulting array is never empty.
Declaration
Swift
public var providers: [AuthenticationProvider] { get }
-
providerExtra
Extension methodAdditional data specific to the provider of the latest identity.
Typically, an OAuth2 provider may provide confidential data such as access or refresh tokens.
This property contains technical data while
providerExtra
contains data about the authenticated user.Declaration
Swift
public var providerExtra: [String : Any] { get }
-
providerUID
Extension methodThe unique identifier of the user for the current identity.
Declaration
Swift
public var providerUID: String { get }
-
providerProfile
Extension methodThe profile of the user for the provider of the latest identity.
This property contains data about the authenticated user while
providerExtra
contains technical data.Declaration
Swift
public var providerProfile: [String : Any] { get }
-
previousProviderIdentities
Extension methodThe previous provider identities.
Declaration
Swift
public var previousProviderIdentities: [AuthenticationProviderIdentity] { get }
-
uid
Extension methodThe unique identifier of the user for the back-end.
Declaration
Swift
public var uid: String { get }
-
eMail
Extension methodThe e-mail of the user, or
nil
when it is unavailable.Declaration
Swift
public var eMail: String? { get }
-
identity
Extension methodThe identity of the user, or
nil
when it is unavailable.When the
provider
isAuthenticationProvider.internal(_:)
, the returned value is theproviderUID
. Otherwise, it is theeMail
value.Declaration
Swift
public var identity: String? { get }
-
avatarURL
Extension methodThe URL of an avatar representing the user, or
nil
when it is unavailable.Declaration
Swift
public var avatarURL: URL? { get }
-
provider
Extension methodThe authentication provider corresponding to this method.
Declaration
Swift
public var provider: AuthenticationProvider { get }
-
internalProvider
Extension methodThe provider.
Declaration
Swift
public var internalProvider: AuthenticationProvider.InternalFamily { get }
-
mode
Extension methodThe authentication mode.
Declaration
Swift
public var mode: Wrapped.Mode { get }
-
sender
Extension methodThe sender to be used by the
AuthenticationProvider.InternalFamily.phone
provider. Whennil
, the default sender, defined on the back-end, is used. This parameter is only meaningful wheninternalProvider
isAuthenticationProvider.InternalFamily.phone
. Otherwise, this value is ignored.Declaration
Swift
public var sender: String? { get }
-
identifier
Extension methodThe unique identifier of the user for the provider.
Declaration
Swift
public var identifier: String? { get }
-
profile
Extension methodThe profile of the user.
This property is used by the
attachIdentity(queue:then:)
method.It is not designed to store business applicative data about the user. For that purpose, use the
DatasyncService
.Declaration
Swift
public var profile: [String : Any] { get nonmutating set }
-
displayName
Extension methodThe display name of the user.
This property is used by the
attachIdentity(queue:then:)
method.Declaration
Swift
public var displayName: String? { get nonmutating set }
-
messageLocale
Extension methodThe locale used for verification and one-time password messages sent to the user.
It must be in the
ll-CC
format, wherell
is the ISO 639 alpha-2 code for the language andCC
is the ISO 3166 alpha-2 code for the country variant.Example:
en-US
When
nil
, the preferred locale of the user contained in the main bundle is used.This property is used by the
requestPasswordResetLink(queue:then:)
,attachIdentity(queue:then:)
andrequestOneTimePassword(queue:then:)
methods.Declaration
Swift
public var messageLocale: String? { get nonmutating set }
-
passwordResetMessageTemplate
Extension methodThe identifier of the template, as defined on the developer console, to use for the password reset message.
This property is used by the
requestPasswordResetLink(queue:then:)
method.Declaration
Swift
public var passwordResetMessageTemplate: String? { get nonmutating set }
-
verificationMessageTemplate
Extension methodThe identifier of the template, as defined on the developer console, to use for the verification message.
This property is used by the
attachIdentity(queue:then:)
method.Declaration
Swift
public var verificationMessageTemplate: String? { get nonmutating set }
-
oneTimePasswordMessageTemplate
Extension methodThe identifier of the template, as defined on the developer console, to use for the one-time password message.
This property is used by the
requestOneTimePassword(queue:then:)
method.Declaration
Swift
public var oneTimePasswordMessageTemplate: String? { get nonmutating set }
-
setIdentifier(_:
Extension method) Sets the unique identifier of the user for the provider.
This method must be called after initializing this instance or just after
AuthenticationService.initializeAuthentication(with:context:)
.Declaration
Swift
@discardableResult public func setIdentifier(_ identifier: String) -> WebcomResult<Void>
Parameters
identifier
The unique identifier of the user for the provider, or
nil
to set it later.Return Value
A
WebcomResult
with a void value in case of success or aWebcomError
value in case of the failure. -
setStaticPassword(_:
Extension method) Sets the static password of the user.
Only use this method if the authentication mode is
Mode.staticPassword
.Declaration
Swift
@discardableResult public func setStaticPassword(_ password: String) -> WebcomResult<Void>
Parameters
password
The password of the user.
Return Value
A
WebcomResult
with a void value in case of success or aWebcomError
value in case of the failure. -
setVerificationToken(_:
Extension method) Sets the verification token sent by the provider for sign-up.
Only use this method if the authentication mode is
Mode.staticPassword
. When authentication mode isMode.oneTimePassword
, use thesetVerificationOneTimePassword(_:)
method instead.Declaration
Swift
@discardableResult public func setVerificationToken(_ token: String) -> WebcomResult<Void>
Parameters
token
The verification token.
Return Value
A
WebcomResult
with a void value in case of success or aWebcomError
value in case of the failure. -
setVerificationOneTimePassword(_:
Extension method) Sets the verification one-time password sent by the provider for sign-up.
Only use this method if the authentication mode is
Mode.oneTimePassword
. When authentication mode isMode.staticPassword
, use thesetVerificationToken(_:)
method instead.Declaration
Swift
@discardableResult public func setVerificationOneTimePassword(_ password: String) -> WebcomResult<Void>
Parameters
password
The verification one-time password.
Return Value
A
WebcomResult
with a void value in case of success or aWebcomError
value in case of the failure. -
setOneTimePassword(_:
Extension method) Sets the one-time password sent by the provider for sign-in.
Only use this method when the authentication mode is
Mode.oneTimePassword
and for sign-in. To set the one-time password for sign-up, use thesetVerificationOneTimePassword(_:)
method instead. To set the static password for sign-up, use thesetStaticPassword(_:)
method instead.Declaration
Swift
@discardableResult public func setOneTimePassword(_ password: String) -> WebcomResult<Void>
Parameters
password
The sign-in one-time password.
Return Value
A
WebcomResult
with a void value in case of success or aWebcomError
value in case of the failure.
-
ongoingAuthentication
Extension methodThe ongoing authentication process.
This property is
nil
when there is no ongoing authentication process.Declaration
Swift
public var ongoingAuthentication: Wrapped.AuthenticationProcess? { get }
-
initializeAuthentication(with:
Extension methodcontext: ) Initializes an authentication process.
After using this method, the
continueAuthentication(queue:then:)
method must be called to continue the authentication process. Some additional steps, depending on themethod
, may be required between the two.The
method
may be any authentication method, but single-steps ones should better useauthenticate(with:queue:then:)
directly, since it includes the call tocontinueAuthentication(queue:then:)
.So, in practice,
method
should be an instance ofAuthenticationMethodInternal
.Declaration
Swift
@discardableResult public func initializeAuthentication(with method: AuthenticationMethod, context: AuthenticationService.Context = .new) -> WebcomResult<Void>
Parameters
method
The authentication method to use for the authentication process.
context
The context to use for the authentication process.
Return Value
A
WebcomResult
with a void value in case of success or aWebcomError
value in case of the failure. -
initializeAuthentication(with:
Extension methodcontext: ) Initializes an authentication process.
After using this method, the
continueAuthentication(queue:then:)
method must be called to continue the authentication process. Some additional steps, depending on themethod
, may be required between the two.The
method
may be any authentication method, but single-steps ones should better useauthenticate(with:queue:then:)
directly, since it includes the call tocontinueAuthentication(queue:then:)
.So, in practice,
method
should be a wrapped instance ofAuthenticationMethodInternal
.Declaration
Swift
@discardableResult public func initializeAuthentication<Method>(with method: Method, context: AuthenticationService.Context = .new) -> WebcomResult<Void> where Method : WebcomWrapper, Method.Wrapped : AuthenticationMethod
Parameters
method
The authentication method to use for the authentication process.
context
The context to use for the authentication process.
Return Value
A
WebcomResult
with a void value in case of success or aWebcomError
value in case of the failure. -
cancelAuthentication()
Extension methodCancels the currently ongoing authentication process.
When there is no ongoing authentication process, this method is a no-op.
Declaration
Swift
public func cancelAuthentication()
-
subscribe(stores:
Extension methodfile: line: queue: onEvent: onCompletion: ) Subscribes to authentication events.
A subscription must always be stored somewhere in order to be cancelled when it is no longer used. Until a subscription is cancelled, it remains active and consumes resources. The easiest way is to let this instance store it by setting the
stores
parameter totrue
(which is its default value). Otherwise, the returned subscription instance must be stored by the application.Subscriptions stored by a
AuthenticationService
are cancelled automatically when it is deinitialized.They can also be cancelled manually:
- individually using the
AuthenticationSubscription.cancel()
method of the returned subscription instance, globally using the
unsubscribeFromAll()
method of this service instance, provided that thestores
parameter was set totrue
.
Declaration
Swift
@discardableResult public func subscribe(stores: Bool = true, file: StaticString = #fileID, line: UInt = #line, queue: DispatchQueue? = nil, onEvent eventCallback: @escaping (_ event: AuthenticationEvent) -> Void, onCompletion completionCallback: (() -> Void)? = nil) -> AuthenticationSubscription?
Parameters
stores
Indicates whether the returned subscription should be stored by this instance.
file
The file from which the method is called. This is used for debugging purposes.
line
The line from which the method is called. This is used for debugging purposes.
queue
The queue to which the provided
eventCallback
andcompletionCallback
dispatch. Whennil
, the default callback queue of the application of this instance is used.eventCallback
The closure to call when an authentication event occurs.
event
The event that occurred.
completionCallback
The closure to call when the subscription completes.
Return Value
An instance describing the subscription, or
nil
if the subscription failed. - individually using the
-
unsubscribeFromAll()
Extension methodCancels all stored subscriptions.
Subscriptions are stored by the
subscribe(stores:file:line:queue:callback:)
method when thestores
parameter is set totrue
(which is its default value).Usually, there is no need to call this method since it is done automatically when this instance is deinitialized.
Declaration
Swift
public func unsubscribeFromAll()
-
path
Extension methodThe absolute path of the node referred by this instance.
The path consists of the keys of the ancestors of this node, starting from the root of the tree, separated by
/
(slash) characters. The last segment of the path is the key of this node. The before last segment of the path, if any, is the key of the parent of this node. The path always begins with a/
. The path of the root node is"/"
.Declaration
Swift
public var path: String { get }
-
key
Extension method
-
service
Extension methodThe service from which this manager comes.
Declaration
Swift
public var service: DatasyncService { get }
-
defaultCompletedSubscriptionPolicy
Extension methodThe policy applied by default to subscriptions created from this manager when they are completed.
A specific policy may be applied to a subscription by setting the
DatasyncSubscription.completedSubscriptionPolicy
property before the completion callback is called.Declaration
Swift
public var defaultCompletedSubscriptionPolicy: DatasyncCompletedSubscriptionPolicy { get }
-
unsubscribeFromAll()
Extension methodCancels all stored subscriptions.
Subscriptions are stored by the
DatasyncNode.subscribe(to:childrenConstraint:stores:file:line:queue:onEvent:onCompletion:)
method with nodes belonging to this manager instance, when thestores
parameter is set totrue
(which is its default value).Usually, there is no need to call this method since it is done automatically when this instance is deinitialized.
Declaration
Swift
public func unsubscribeFromAll()
-
date(fromPushIdentifier:
Extension method) Returns the creation date of a timestamp-based node key.
Warning
This method was deprecated in version 2.2.0. UsepushIdentifier.date
instead.Declaration
Swift
@available(*, deprecated, renamed: "WebcomKey.date") public func date(fromPushIdentifier pushIdentifier: WebcomKey) -> Date?
-
encodedKey(from:
Extension method) Encodes the input string to get a value that may be used as a valid node key. Returns a string that may be used as a valid node key to represent a given value.
The returned value may be decoded as follow to retrieve the input value:
- in Swift, use the
removingPercentEncoding
property, in JavaScript (e.g. for security rules), use the
decodeURIComponent()
global function.
Declaration
Swift
public func encodedKey(from rawKey: String) -> String?
Parameters
rawKey
The input string to encode.
Return Value
An encoded form of the input string, or
nil
when the input string cannot be encoded. - in Swift, use the
-
runOnlyFirstTime(_:
Extension method) Runs a block the first time this method is used for a given instance.
The first time this method is called for a given instance, the
block
is run. On subsequent calls on the same instance, this method is a no-operation, whether theblock
is the same of different from the first call.This method is designed to be used in the
viewDidAppear(_:)
or theviewWillAppear(_:)
method of a view controller to do some subscriptions, that need the user interface to be already loaded.Declaration
Swift
public func runOnlyFirstTime(_ block: () -> Void)
Parameters
block
The block to run.
-
path
Extension methodThe absolute path of the node referred by this instance.
The path consists of the keys of the ancestors of this node, starting from the root of the tree, separated by
/
(slash) characters. The last segment of the path is the key of this node. The before last segment of the path, if any, is the key of the parent of this node. The path always begins with a/
. The path of the root node is"/"
.Declaration
Swift
public var path: String { get }
-
key
Extension method -
cacheValue
Extension methodThe value of the node referred by this instance from the cache.
When there is no value available in the cache, the returned value is
null
(not to be confused with the Swiftnil
keyword).In general, to get the value of a node, it is preferable to use the
value(queue:then:)
method.Declaration
Swift
public var cacheValue: DatasyncValue { get }
-
assignChildren(to:
Extension methodon: stores: queue: file: line: ) Creates a subscription that assigns the children of the referred node to a dictionary.
In the dictionary:
- the keys are the keys of the children, as returned by
DatasyncEvent.key
, - the values are decoded from the values of the children using
DatasyncValue.decoded()
.
This method uses an underlying subscription to follow children additions, changes and removals. The dictionary is updated each time an event is received for that subscription. If the value of an added or changed child could not be decoded, the corresponding element in the dictionary is removed. If the subscription is revoked by the back-end, the dictionary is cleared.
Depending on
stores
, the subscription may be stored by theDatasyncManager
of the referred node, as thesubscribe(to:childrenConstraint:stores:file:line:queue:onEvent:onCompletion:)
method does.To avoid a retain cycle, the subscription does not keep a strong reference on the
object
. The developer must ensure that its lifetime is at least as long as that of the subscription. This is the case when the dictionary and theDatasyncManager
are stored in the same object, provided thatstores
istrue
.Example:
class EmployeeDirectory { struct Employee: Decodable { let name: String let yearOfBirth: Int } let datasyncManager = Webcom.defaultApplication.datasyncService.createManager() var employees: [String: Employee] = [:] func assignEmployees() { let employeesNode = datasyncManager / "employees" employeesNode?.assignChildren(to: \.employees, on: self) } ... }
Declaration
Swift
@discardableResult public func assignChildren<R>(to keyPath: ReferenceWritableKeyPath<R, [WebcomKey : some Decodable]>, on object: R, stores: Bool = true, queue: DispatchQueue? = nil, file: StaticString = #fileID, line: UInt = #line) -> DatasyncSubscription? where R : AnyObject
Parameters
keyPath
A key path that indicates the dictionary property to assign.
object
The object that contains the dictionary property to assign.
stores
Indicates whether the returned subscription should be stored by the manager.
queue
The queue to which dictionary updates are dispatched. When
nil
, the default callback queue of the manager of this instance is used.file
The file from which the method is called. This is used for debugging purposes.
line
The line from which the method is called. This is used for debugging purposes.
Return Value
An instance describing the underlying subscription, or
nil
if the subscription failed. - the keys are the keys of the children, as returned by
-
cancelNextDisconnectionAction()
Extension methodCancels an operation registered using the
DatasyncTime.nextDisconnection
value for the node referred by this instance.If no operation is currently registered, this method has no effect. This method cannot cancel an operation that has already been performed by the back-end.
Declaration
Swift
public func cancelNextDisconnectionAction()
-
state
Extension methodThe states of the web socket opened by this service.
Declaration
Swift
public var state: DatasyncState { get }
-
isConnectionEnabled
Extension methodIndicates whether the connection of the web socket associated to this service is enabled.
When an instance is initialized, this property is
true
. The SDK never modifies it from its own.When this property is
true
, the web socket connects as soon as there is network connectivity and the application is in foreground. When this property isfalse
, the web socket disconnects.Declaration
Swift
public var isConnectionEnabled: Bool { get nonmutating set }
-
cache
Extension methodThe cache.
See
WebcomConfiguration.CacheMode
for know when this property is usable or not.The format of the returned string is opaque. A
nil
value indicates that the cache could not be retrieved.Declaration
Swift
public var cache: String? { get }
-
cleanCache()
Extension methodCleans the cache and stop updating it for all already cancelled subscriptions.
Calling this method is equivalent to having used the
DatasyncCompletedSubscriptionPolicy.forgetData
policy for all theDatasyncSubscription
instances linked to this service completed so far. However, this has no effect on future cancellations or revocations.Declaration
Swift
public func cleanCache()
-
saveCache()
Extension methodSaves the cache.
See
WebcomConfiguration.CacheMode
for know when this method is usable or not.Declaration
Swift
@discardableResult public func saveCache() -> Bool
-
startPublishingMyPresence(on:
Extension methodfile: line: ) Starts publishing the presence of the current user.
A user is said to be present when he/she is authenticated and connected on at least one device. A user is connected when the web socket of the Datasync service is connected with the back-end.
The presence is represented with the value of a node using an unspecified format. The presence is published until the
stopPublishingMyPresence()
method is called or the current user become unauthenticated.The presence of the user can only be published on one node at a time. When this method is called, any presence publication already started is stopped before processing further.
Declaration
Swift
public func startPublishingMyPresence(on path: String, file: StaticString = #fileID, line: UInt = #line)
Parameters
path
The path of the node where to store the presence status of the current user.
file
The file from which the method is called. This is used for debugging purposes.
line
The line from which the method is called. This is used for debugging purposes.
-
stopPublishingMyPresence()
Extension methodStops publishing the presence of the current user.
When the presence of the current user is currently not published, this method is a no-operation. Use the
startPublishingMyPresence(on:file:line:)
method to start publishing the presence of the current user.Declaration
Swift
public func stopPublishingMyPresence()
-
isPresent(state:
Extension method) Indicates whether a user is currently present.
This method is designed to work in concert with the
startPublishingMyPresence(on:file:line:)
method. This method analyzes the value of a node whose value corresponds to the presence state of another user, in the sense of the latter method.Declaration
Swift
public func isPresent(state: WebcomPresenceState?) -> Bool
Parameters
state
The value of a node corresponding to the presence state of a user.
Return Value
true
whennodeValue
corresponds to a present user,false
otherwise.
-
configuration
Extension methodThe configuration corresponding to this application.
Declaration
Swift
public var configuration: WebcomConfiguration { get }
-
defaultSession
Extension methodThe
URLSession
instance used by this application.When this property is
nil
,Webcom.defaultSession
is used instead.Declaration
Swift
public var defaultSession: URLSession? { get nonmutating set }
-
defaultCallbackQueue
Extension methodThe
DispatchQueue
used by default to schedule callbacks.When this property is
nil
,Webcom.defaultCallbackQueue
is used instead.Declaration
Swift
public var defaultCallbackQueue: DispatchQueue? { get nonmutating set }
-
jsonEncoder
Extension methodThe
JSONEncoder
instance used to serialize data for this application.This property is initialized using the
createDefaultJSONEncoder()
static function.Declaration
Swift
public var jsonEncoder: JSONEncoder { get nonmutating set }
-
jsonDecoder
Extension methodThe
JSONDecoder
instance used to deserialize data for this application.This property is initialized using the
createDefaultJSONDecoder()
static function.Declaration
Swift
public var jsonDecoder: JSONDecoder { get nonmutating set }
-
createDefaultJSONEncoder()
Extension methodReturns a new JSON encoder.
The returned instance is configured with:
iso8601
date encoding strategy,base64
data encoding strategy.
This function is used to initialize the
jsonEncoder
property of instances.Declaration
Swift
public static func createDefaultJSONEncoder() -> JSONEncoder
Return Value
A new
JSONEncoder
instance -
createDefaultJSONDecoder()
Extension methodReturns a new JSON decoder.
The returned instance is configured with:
iso8601
date decoding strategy,base64
data decoding strategy.
This function is used to initialize the
jsonDecoder
property of instances.Declaration
Swift
public static func createDefaultJSONDecoder() -> JSONDecoder
Return Value
A new
JSONDecoder
instance -
identifier
Extension methodThe identifier of this application on the back-end.
Declaration
Swift
public var identifier: String { get }