BridgeManager

public final class BridgeManager

Singleton-class for managing global setup of subaio-views. Before creating views, BridgeManager.shared.configure should be invoked and BridgeManager.shared.language should be assigned.

The manager automatically maintains a valid token and requests new ones using the onTokenRequired callback whenever necessary.

  • Shared instance of the BridgeManager.

    Declaration

    Swift

    public static let shared: BridgeManager
  • Language to be used by all BridgeViews as a BCP-47 string. Assigning language automatically updates all views and triggers a token refetch if configure has already been called. If it is set to nil or not set, views will never exit their loading-state.

    Declaration

    Swift

    public var language: String? { get set }
  • URL pointing to root of Subaio template, e.g. if template is at https://www.bar.foo/template, then baseUrl should be https://www.bar.foo.

    Declaration

    Swift

    public private(set) var baseUrl: URL? { get }
  • Controls whether or not Subaio is allowed to open external URLs.

    Declaration

    Swift

    public private(set) var allowExternalUrls: Bool { get }
  • Controls whether or not Subaio is allowed to open a share-dialog (should be implemented in the BridgeViewDelegate protocol as isAttemptingToShare).

    Declaration

    Swift

    public private(set) var allowShare: Bool { get }
  • Configuration for SSL pinning.

    Declaration

    Swift

    public private(set) var authenticationChallenger: AuthenticationChallenger? { get }
  • Callback invoked when token needs to be refreshed. Implementations should take care that the supplied completionHandler is always invoked at some point.

    Declaration

    Swift

    public private(set) var onTokenRequired: TokenRequiredCallback? { get }
  • Custom key-value pairs sent to all BridgeViews. These should be agreed upon before-hand. Useful for runtime theming, light/dark mode etc.

    Declaration

    Swift

    public var customConfig: [String : String]? { get set }
  • Undocumented

    Declaration

    Swift

    public init()
  • Configure the BridgeManager before creating BridgeViews.

    Declaration

    Swift

    public func configure(
        baseUrl: URL,
        language: String? = nil,
        allowExternalUrls: Bool? = nil,
        allowShare: Bool? = nil,
        authenticationChallenger: AuthenticationChallenger,
        onTokenRequired: @escaping TokenRequiredCallback,
        customConfig: [String: String]? = nil
    )

    Parameters

    baseUrl

    The URL where the embedded app is hosted.

    language

    A BCP-47 language tag. The language can be changed on the fly.

    allowExternalUrls

    Allow the embedded app to open arbitrary URLs on the phone.

    allowShare

    Allow the embedded app to request a share dialog to share a message.

    authenticationChallenger

    Handler for SSL pinning and other connection authentication.

    onTokenRequired

    Callback to request a new token. See Authentication section and platform-specific documentation for details. The callback will be called whenever the BridgeManager needs new token information.

    customConfig

    Custom key/values sent to the views. Keys and possible values should be agreed upon between the embedded and host apps. Possible uses are custom theming, dark/light mode and injecting user info.

  • Undocumented

    Declaration

    Swift

    public func prewarm()
  • Force a refresh of the token. This is necessary if the user changes authentication status (user logs out, user logs in, user is changed) to ensure that the token (or lack thereof) is correct.

    Only works after configure has been called and language has been set.

    If no views are currently open, a new token is fetched when a view is created instead.

    Declaration

    Swift

    public func refreshToken()