DropboxClientsManager

public class DropboxClientsManager

This is a convenience class for the typical single user case. To use this class, see details in the tutorial at: https://www.dropbox.com/developers/documentation/swift#tutorial

For information on the available API methods, see the documentation for DropboxClient

  • An authorized client. This will be set to nil if unlinked.

    Declaration

    Swift

    public static var authorizedClient: DropboxClient?
  • An authorized background client. This will be set to nil if unlinked.

    Declaration

    Swift

    public static var authorizedBackgroundClient: DropboxClient?
  • Authorized background clients created in the course of handling background events from extensions, keyed by session identifiers.

    Declaration

    Swift

    public static var authorizedExtensionBackgroundClients: [String : DropboxClient]
  • An authorized team client. This will be set to nil if unlinked.

    Declaration

    Swift

    public static var authorizedTeamClient: DropboxTeamClient?
  • A sdk-caller provided logger

    Declaration

    Swift

    public static var loggingClosure: LoggingClosure?
  • The installed version of the SDK

    Declaration

    Swift

    public static var sdkVersion: String { get }
  • Handle a redirect and automatically initialize the client and save the token.

    Declaration

    Swift

    @discardableResult
    public static func handleRedirectURL(
        _ url: URL,
        includeBackgroundClient: Bool,
        transportClient: DropboxTransportClient? = nil,
        backgroundSessionTransportClient: DropboxTransportClient? = nil,
        sessionConfiguration: NetworkSessionConfiguration? = nil,
        backgroundSessionConfiguration: NetworkSessionConfiguration? = nil,
        completion: @escaping DropboxOAuthCompletion
    ) -> Bool

    Parameters

    url

    The URL to attempt to handle.

    includeBackgroundClient

    Whether to additionally initialize an authorized background client.

    completion

    The callback closure to receive auth result.

    Return Value

    Whether the redirect URL can be handled.

  • Handle a redirect and automatically initialize the client and save the token.

    Declaration

    Swift

    @discardableResult
    public static func handleRedirectURL(
        _ url: URL,
        backgroundSessionIdentifier: String,
        sharedContainerIdentifier: String? = nil,
        completion: @escaping DropboxOAuthCompletion
    ) -> Bool

    Parameters

    url

    The URL to attempt to handle.

    backgroundSessionIdentifier

    The URLSession identifier to use for the background client

    sharedContainerIdentifier

    The URLSessionConfiguration shared container identifier to use for the background client

    completion

    The callback closure to receive auth result.

    Return Value

    Whether the redirect URL can be handled.

  • Handle a redirect and automatically initialize the client and save the token.

    Declaration

    Swift

    @discardableResult
    public static func handleRedirectURLTeam(
        _ url: URL,
        transportClient: DropboxTransportClient? = nil,
        sessionConfiguration: NetworkSessionConfiguration? = nil,
        completion: @escaping DropboxOAuthCompletion
    ) -> Bool

    Parameters

    url

    The URL to attempt to handle.

    completion

    The callback closure to receive auth result.

    Return Value

    Whether the redirect URL can be handled.

  • Prepare the appropriate single user DropboxClient to handle incoming background session events and make ongoing tasks available for reconnection

    Declaration

    Swift

    public static func handleEventsForBackgroundURLSession(
        with identifier: String,
        creationInfos: [BackgroundExtensionSessionCreationInfo],
        completionHandler: @escaping () -> Void,
        requestsToReconnect: @escaping ([Result<DropboxBaseRequestBox, ReconnectionError>]) -> Void
    )

    Parameters

    identifier

    The identifier of the URLSession for which events must be handled.

    creationInfos

    Information to configure extension DropboxClients in the event that they must be recreated in the main app to handle events.

    completionHandler

    The completion handler to be executed when the underlying URLSessionDelegate recieves urlSessionDidFinishEvents(forBackgroundURLSession:).

    requestsToReconnect

    The callback closure to receive requests for reconnection.

  • Prepare the appropriate multiuser DropboxClient to handle incoming background session events and make ongoing tasks available for reconnection

    Declaration

    Swift

    public static func handleEventsForBackgroundURLSessionMultiUser(
        with identifier: String,
        tokenUid: String,
        creationInfos: [BackgroundExtensionSessionCreationInfo],
        completionHandler: @escaping () -> Void,
        requestsToReconnect: @escaping ([Result<DropboxBaseRequestBox, ReconnectionError>]) -> Void
    )

    Parameters

    identifier

    The identifier of the URLSession for which events must be handled.

    tokenUid

    The uid of the token to authenticate this client with.

    creationInfos

    Information to configure extension DropboxClients in the event that they must be recreated in the main app to handle events.

    completionHandler

    The completion handler to be executed when the underlying URLSessionDelegate recieves urlSessionDidFinishEvents(forBackgroundURLSession:).

    requestsToReconnect

    The callback closure to receive requests for reconnection.

  • Unlink the user.

    Declaration

    Swift

    public static func unlinkClients()
  • Unlink the user.

    Declaration

    Swift

    public static func resetClients()
  • Logs to the provided logging closure

    Declaration

    Swift

    public static func log(_ level: LogLevel, _ message: String)
  • Logs to the provided logging closure with background session tag and log level.

    Declaration

    Swift

    public static func logBackgroundSession(_ message: String)
  • Logs to the provided logging closure with background session tag.

    Declaration

    Swift

    public static func logBackgroundSession(_ level: LogLevel, _ message: String)
  • Starts a “token” flow.

    This method should no longer be used. Long-lived access tokens are deprecated. See https://dropbox.tech/developers/migrating-app-permissions-and-access-tokens. Please use authorizeFromControllerV2 instead.

    Declaration

    Swift

    @available(*, deprecated, message: "This method was used for long-lived access tokens, which are now deprecated. Please use `authorizeFromControllerV2` instead.")
    public static func authorizeFromController(
        sharedApplication: NSApplication,
        controller: NSViewController?,
        openURL: @escaping ((URL) -> Void)
    )

    Parameters

    sharedApplication

    The shared NSApplication instance in your app.

    controller

    An NSViewController to present the auth flow from. Reference is weakly held.

    openURL

    Handler to open a URL.

  • Starts the OAuth 2 Authorization Code Flow with PKCE.

    PKCE allows “authorization code” flow without “client_secret” It enables “native application”, which is ensafe to hardcode client_secret in code, to use “authorization code”. PKCE is more secure than “token” flow. If authorization code is compromised during transmission, it can’t be used to exchange for access token without random generated code_verifier, which is stored inside this SDK.

    Note

    If auth completes successfully, A short-lived Access Token and a long-lived Refresh Token will be granted. API calls with expired Access Token will fail with AuthError. An expired Access Token must be refreshed in order to continue to access Dropbox APIs.

    API clients set up by DropboxClientsManager will get token refresh logic for free. If you need to set up DropboxClient/DropboxTeamClient without DropboxClientsManager, you will have to set up the clients with an appropriate AccessTokenProvider.

    Declaration

    Swift

    public static func authorizeFromControllerV2(
        sharedApplication: NSApplication,
        controller: NSViewController?,
        loadingStatusDelegate: LoadingStatusDelegate?,
        openURL: @escaping ((URL) -> Void),
        scopeRequest: ScopeRequest?
    )

    Parameters

    sharedApplication

    The shared NSWorkspace instance in your app.

    controller

    An NSViewController to present the auth flow from. Reference is weakly held.

    loadingStatusDelegate

    An optional delegate to handle loading experience during auth flow. e.g. Show a loading spinner and block user interaction while loading/waiting.

    openURL

    Handler to open a URL.

    scopeRequest

    Contains requested scopes to obtain.

  • Starts a “token” flow.

    This method should no longer be used. Long-lived access tokens are deprecated. See https://dropbox.tech/developers/migrating-app-permissions-and-access-tokens. Please use authorizeFromControllerV2 instead.

    Declaration

    Swift

    @available(*, deprecated, message: "This method was used for long-lived access tokens, which are now deprecated. Please use `authorizeFromControllerV2` instead.")
    public static func authorizeFromController(
        _ sharedApplication: UIApplication,
        controller: UIViewController?,
        openURL: @escaping ((URL) -> Void)
    )

    Parameters

    sharedApplication

    The shared UIApplication instance in your app.

    controller

    A UIViewController to present the auth flow from. This should be the top-most view controller. Reference is weakly held.

    openURL

    Handler to open a URL.

  • Starts the OAuth 2 Authorization Code Flow with PKCE.

    PKCE allows “authorization code” flow without “client_secret” It enables “native application”, which is ensafe to hardcode client_secret in code, to use “authorization code”. PKCE is more secure than “token” flow. If authorization code is compromised during transmission, it can’t be used to exchange for access token without random generated code_verifier, which is stored inside this SDK.

    Note

    If auth completes successfully, A short-lived Access Token and a long-lived Refresh Token will be granted. API calls with expired Access Token will fail with AuthError. An expired Access Token must be refreshed in order to continue to access Dropbox APIs.

    API clients set up by DropboxClientsManager will get token refresh logic for free. If you need to set up DropboxClient/DropboxTeamClient without DropboxClientsManager, you will have to set up the clients with an appropriate AccessTokenProvider.

    Declaration

    Swift

    public static func authorizeFromControllerV2(
        _ sharedApplication: UIApplication,
        controller: UIViewController?,
        loadingStatusDelegate: LoadingStatusDelegate?,
        openURL: @escaping ((URL) -> Void),
        scopeRequest: ScopeRequest?
    )

    Parameters

    sharedApplication

    The shared UIApplication instance in your app.

    controller

    A UIViewController to present the auth flow from. This should be the top-most view controller. Reference is weakly held.

    loadingStatusDelegate

    An optional delegate to handle loading experience during auth flow. e.g. Show a loading spinner and block user interaction while loading/waiting. If a delegate is not provided, the SDK will show a default loading spinner when necessary.

    openURL

    Handler to open a URL.

    scopeRequest

    Contains requested scopes to obtain.