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 SyncUser representing the logged-in user will be passed to it. This user object can be used to open Realms and retrieve SyncSessions. 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

    credentials

    A SyncCredentials object representing the user to log in.

    authServerURL

    The URL of the authentication server (e.g. http://realm.example.org:9080).

    timeout

    How long the network client should wait, in seconds, before timing out.

    callbackQueue

    The dispatch queue upon which the callback should run. Defaults to the main queue.

    completion

    A callback block to be invoked once the log in completes.

  • all

    A dictionary of all valid, logged-in user identities corresponding to their SyncUser objects.

    Declaration

    Swift

    public static var all: [String : SyncUser] { get }
  • The logged-in user. nil if 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 .invalidAccessToken to 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

    url

    The 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.

    accessLevel

    What access level to grant to whoever accepts the token.

    expiration

    Optionally, 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.

    callback

    A 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.

    enableSSLValidation is 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.lock or .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
  • 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.Configuration

    Parameters

    realmURL

    The 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.lock or .realm.management.

    serverValidationPolicy

    How 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 .pinCertificate to pin a specific SSL certificate, or .none for debugging.

    fullSynchronization

    Whether this Realm should be a fully synchronized or a query-based Realm.

    urlPrefix

    The 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.

    cancelAsyncOpenOnNonFatalErrors

    By 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.