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 }
-
authenticationTokenExtension methodThe authentication token.
Declaration
Swift
public var authenticationToken: String { get } -
creationDateExtension methodThe creation date of the user account.
Declaration
Swift
public var creationDate: Date { get } -
displayNameExtension methodThe display name of the user, or
nilwhen it is unavailable.Declaration
Swift
public var displayName: String? { get } -
expirationDateExtension methodThe expiration date of the authentication.
Declaration
Swift
public var expirationDate: Date { get } -
providerExtension methodThe provider of the current identity.
Declaration
Swift
public var provider: AuthenticationProvider { get } -
providersExtension 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 } -
providerExtraExtension 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
providerExtracontains data about the authenticated user.Declaration
Swift
public var providerExtra: [String : Any] { get } -
providerUIDExtension methodThe unique identifier of the user for the current identity.
Declaration
Swift
public var providerUID: String { get } -
providerProfileExtension methodThe profile of the user for the provider of the latest identity.
This property contains data about the authenticated user while
providerExtracontains technical data.Declaration
Swift
public var providerProfile: [String : Any] { get } -
previousProviderIdentitiesExtension methodThe previous provider identities.
Declaration
Swift
public var previousProviderIdentities: [AuthenticationProviderIdentity] { get } -
uidExtension methodThe unique identifier of the user for the back-end.
Declaration
Swift
public var uid: String { get } -
eMailExtension methodThe e-mail of the user, or
nilwhen it is unavailable.Declaration
Swift
public var eMail: String? { get } -
identityExtension methodThe identity of the user, or
nilwhen it is unavailable.When the
providerisAuthenticationProvider.internal(_:), the returned value is theproviderUID. Otherwise, it is theeMailvalue.Declaration
Swift
public var identity: String? { get } -
avatarURLExtension methodThe URL of an avatar representing the user, or
nilwhen it is unavailable.Declaration
Swift
public var avatarURL: URL? { get }
-
providerExtension methodThe authentication provider corresponding to this method.
Declaration
Swift
public var provider: AuthenticationProvider { get }
-
internalProviderExtension methodThe provider.
Declaration
Swift
public var internalProvider: AuthenticationProvider.InternalFamily { get } -
modeExtension methodThe authentication mode.
Declaration
Swift
public var mode: Wrapped.Mode { get } -
senderExtension methodThe sender to be used by the
AuthenticationProvider.InternalFamily.phoneprovider. Whennil, the default sender, defined on the back-end, is used. This parameter is only meaningful wheninternalProviderisAuthenticationProvider.InternalFamily.phone. Otherwise, this value is ignored.Declaration
Swift
public var sender: String? { get } -
identifierExtension methodThe unique identifier of the user for the provider.
Declaration
Swift
public var identifier: String? { get } -
profileExtension 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 } -
displayNameExtension 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 } -
messageLocaleExtension methodThe locale used for verification and one-time password messages sent to the user.
It must be in the
ll-CCformat, wherellis the ISO 639 alpha-2 code for the language andCCis the ISO 3166 alpha-2 code for the country variant.Example:
en-USWhen
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 } -
passwordResetMessageTemplateExtension 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 } -
verificationMessageTemplateExtension 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 } -
oneTimePasswordMessageTemplateExtension 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
identifierThe unique identifier of the user for the provider, or
nilto set it later.Return Value
A
WebcomResultwith a void value in case of success or aWebcomErrorvalue 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
passwordThe password of the user.
Return Value
A
WebcomResultwith a void value in case of success or aWebcomErrorvalue 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
tokenThe verification token.
Return Value
A
WebcomResultwith a void value in case of success or aWebcomErrorvalue 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
passwordThe verification one-time password.
Return Value
A
WebcomResultwith a void value in case of success or aWebcomErrorvalue 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.oneTimePasswordand 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
passwordThe sign-in one-time password.
Return Value
A
WebcomResultwith a void value in case of success or aWebcomErrorvalue in case of the failure.
-
ongoingAuthenticationExtension methodThe ongoing authentication process.
This property is
nilwhen 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
methodmay 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,
methodshould be an instance ofAuthenticationMethodInternal.Declaration
Swift
@discardableResult public func initializeAuthentication(with method: AuthenticationMethod, context: AuthenticationService.Context = .new) -> WebcomResult<Void>Parameters
methodThe authentication method to use for the authentication process.
contextThe context to use for the authentication process.
Return Value
A
WebcomResultwith a void value in case of success or aWebcomErrorvalue 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
methodmay 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,
methodshould 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 : AuthenticationMethodParameters
methodThe authentication method to use for the authentication process.
contextThe context to use for the authentication process.
Return Value
A
WebcomResultwith a void value in case of success or aWebcomErrorvalue 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
storesparameter totrue(which is its default value). Otherwise, the returned subscription instance must be stored by the application.Subscriptions stored by a
AuthenticationServiceare 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 thestoresparameter 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
storesIndicates whether the returned subscription should be stored by this instance.
fileThe file from which the method is called. This is used for debugging purposes.
lineThe line from which the method is called. This is used for debugging purposes.
queueThe queue to which the provided
eventCallbackandcompletionCallbackdispatch. Whennil, the default callback queue of the application of this instance is used.eventCallbackThe closure to call when an authentication event occurs.
eventThe event that occurred.
completionCallbackThe closure to call when the subscription completes.
Return Value
An instance describing the subscription, or
nilif 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 thestoresparameter 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()
-
pathExtension 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 } -
keyExtension method
-
serviceExtension methodThe service from which this manager comes.
Declaration
Swift
public var service: DatasyncService { get } -
defaultCompletedSubscriptionPolicyExtension 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.completedSubscriptionPolicyproperty 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 thestoresparameter 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.dateinstead.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
removingPercentEncodingproperty, in JavaScript (e.g. for security rules), use the
decodeURIComponent()global function.
Declaration
Swift
public func encodedKey(from rawKey: String) -> String?Parameters
rawKeyThe input string to encode.
Return Value
An encoded form of the input string, or
nilwhen 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
blockis run. On subsequent calls on the same instance, this method is a no-operation, whether theblockis 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
blockThe block to run.
-
pathExtension 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 } -
keyExtension method -
cacheValueExtension 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 Swiftnilkeyword).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 theDatasyncManagerof 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 theDatasyncManagerare stored in the same object, provided thatstoresistrue.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 : AnyObjectParameters
keyPathA key path that indicates the dictionary property to assign.
objectThe object that contains the dictionary property to assign.
storesIndicates whether the returned subscription should be stored by the manager.
queueThe queue to which dictionary updates are dispatched. When
nil, the default callback queue of the manager of this instance is used.fileThe file from which the method is called. This is used for debugging purposes.
lineThe line from which the method is called. This is used for debugging purposes.
Return Value
An instance describing the underlying subscription, or
nilif the subscription failed. - the keys are the keys of the children, as returned by
-
cancelNextDisconnectionAction()Extension methodCancels an operation registered using the
DatasyncTime.nextDisconnectionvalue 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()
-
stateExtension methodThe states of the web socket opened by this service.
Declaration
Swift
public var state: DatasyncState { get } -
isConnectionEnabledExtension 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 } -
cacheExtension methodThe cache.
See
WebcomConfiguration.CacheModefor know when this property is usable or not.The format of the returned string is opaque. A
nilvalue 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.forgetDatapolicy for all theDatasyncSubscriptioninstances 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.CacheModefor 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
pathThe path of the node where to store the presence status of the current user.
fileThe file from which the method is called. This is used for debugging purposes.
lineThe 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?) -> BoolParameters
stateThe value of a node corresponding to the presence state of a user.
Return Value
truewhennodeValuecorresponds to a present user,falseotherwise.
-
configurationExtension methodThe configuration corresponding to this application.
Declaration
Swift
public var configuration: WebcomConfiguration { get } -
defaultSessionExtension methodThe
URLSessioninstance used by this application.When this property is
nil,Webcom.defaultSessionis used instead.Declaration
Swift
public var defaultSession: URLSession? { get nonmutating set } -
defaultCallbackQueueExtension methodThe
DispatchQueueused by default to schedule callbacks.When this property is
nil,Webcom.defaultCallbackQueueis used instead.Declaration
Swift
public var defaultCallbackQueue: DispatchQueue? { get nonmutating set } -
jsonEncoderExtension methodThe
JSONEncoderinstance 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 } -
jsonDecoderExtension methodThe
JSONDecoderinstance 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:
iso8601date encoding strategy,base64data encoding strategy.
This function is used to initialize the
jsonEncoderproperty of instances.Declaration
Swift
public static func createDefaultJSONEncoder() -> JSONEncoderReturn Value
A new
JSONEncoderinstance -
createDefaultJSONDecoder()Extension methodReturns a new JSON decoder.
The returned instance is configured with:
iso8601date decoding strategy,base64data decoding strategy.
This function is used to initialize the
jsonDecoderproperty of instances.Declaration
Swift
public static func createDefaultJSONDecoder() -> JSONDecoderReturn Value
A new
JSONDecoderinstance -
identifierExtension methodThe identifier of this application on the back-end.
Declaration
Swift
public var identifier: String { get }