SyncUser
extension SyncUser
-
Log in a user and asynchronously retrieve a user object.
If the log in completes successfully, the completion block will be called, and a
SyncUserrepresenting the logged-in user will be passed to it. This user object can be used to openRealms and retrieveSyncSessions. Otherwise, the completion block will be called with an error.Declaration
Swift
public static func logIn(with credentials: SyncCredentials, server authServerURL: URL, timeout: TimeInterval = 30, callbackQueue queue: DispatchQueue = DispatchQueue.main, onCompletion completion: @escaping UserCompletionBlock)Parameters
credentialsA
SyncCredentialsobject representing the user to log in.authServerURLThe URL of the authentication server (e.g.
http://realm.example.org:9080
).timeoutHow long the network client should wait, in seconds, before timing out.
callbackQueueThe dispatch queue upon which the callback should run. Defaults to the main queue.
completionA callback block to be invoked once the log in completes.
-
The logged-in user.
nilif none exists. Only use this property if your application expects no more than one logged-in user at any given time.Warning
Throws an Objective-C exception if more than one logged-in user exists.Declaration
Swift
public static var current: SyncUser? { get } -
An optional error handler which can be set to notify the host application when the user encounters an error.
Note
Check for
.invalidAccessTokento see if the user has been remotely logged out because its refresh token expired, or because the third party authentication service providing the user’s identity has logged the user out.Warning
Regardless of whether an error handler is defined, certain user errors will automatically cause the user to enter the logged out state.
Declaration
Swift
@nonobjc public var errorHandler: ((SyncUser, SyncAuthError) -> Void)? { get set } -
Create a permission offer for a Realm.
A permission offer is used to grant access to a Realm this user manages to another user. Creating a permission offer produces a string token which can be passed to the recepient in any suitable way (for example, via e-mail).
The operation will take place asynchronously. The token can be accepted by the recepient using the
SyncUser.acceptOffer(forToken:, callback:)method.Declaration
Swift
public func createOfferForRealm(at url: URL, accessLevel: SyncAccessLevel, expiration: Date? = nil, callback: @escaping (String?, Error?) -> Void)Parameters
urlThe URL of the Realm for which the permission offer should pertain. This may be the URL of any Realm which this user is allowed to manage. If the URL has a
~wildcard it will be replaced with this user’s user identity.accessLevelWhat access level to grant to whoever accepts the token.
expirationOptionally, a date which indicates when the offer expires. If the recepient attempts to accept the offer after the date it will be rejected. If nil, the offer will never expire.
callbackA callback indicating whether the operation succeeded or failed. If it succeeded the token will be passed in as a string.
-
Create a sync configuration instance.
Additional settings can be optionally specified. Descriptions of these settings follow.
enableSSLValidationis true by default. It can be disabled for debugging purposes.Warning
The URL must be absolute (e.g.
realms://example.com/~/foo), and cannot end with.realm,.realm.lockor.realm.management.Warning
NEVER disable SSL validation for a system running in production.
Declaration
Swift
public func configuration(realmURL: URL? = nil, fullSynchronization: Bool = false, enableSSLValidation: Bool, urlPrefix: String? = nil) -> Realm.Configuration -
configuration(realmURL:fullSynchronization:serverValidationPolicy:urlPrefix:cancelAsyncOpenOnNonFatalErrors:)Create a sync configuration instance.
Warning
NEVER disable SSL validation for a system running in production.
Declaration
Swift
public func configuration(realmURL: URL? = nil, fullSynchronization: Bool = false, serverValidationPolicy: ServerValidationPolicy = .system, urlPrefix: String? = nil, cancelAsyncOpenOnNonFatalErrors: Bool = false) -> Realm.ConfigurationParameters
realmURLThe URL to connect to. If not set, the default Realm derived from the authentication URL is used. The URL must be absolute (e.g.
realms://example.com/~/foo), and cannot end with.realm,.realm.lockor.realm.management.serverValidationPolicyHow the SSL certificate of the Realm Object Server should be validated. By default the system SSL validation is used, but it can be set to
.pinCertificateto pin a specific SSL certificate, or.nonefor debugging.fullSynchronizationWhether this Realm should be a fully synchronized or a query-based Realm.
urlPrefixThe prefix that is prepended to the path in the HTTP request that initiates a sync connection. The value specified must match with the server’s expectation, and this parameter only needs to be set if you have changed the configuration of the server.
cancelAsyncOpenOnNonFatalErrorsBy default, Realm.asyncOpen() swallows non-fatal connection errors such as a connection attempt timing out and simply retries until it succeeds. If this is set to
true, instead the error will be reported to the callback and the async open will be cancelled.
View on GitHub
Install in Dash
SyncUser Extension Reference