UsageBroker

open class UsageBroker

High-level wrapper around Usage API implemented as a singleton to encapsulate lifecycle events (optional sessions), and uploading of usage event logs.

  • Static constant property that provides access to the UsageBroker singleton class.

    Declaration

    Swift

    public static let shared: UsageBroker
  • Read-only access to UsageBroker UsageStore class required for usage record activities.

    Declaration

    Swift

    private(set) public var store: UsageStore?
  • Read-only access to InjectOSlifecycleSession property set during start method.

    Declaration

    Swift

    private(set) public var injectOSlifecycleSession: Bool
  • Read-only access to DataCollectionItems property set during start method.

    Declaration

    Swift

    private(set) public var collectionItems: UsageDataCollectionItems
  • SAPURLSession required for uploading usage event logs.

    Declaration

    Swift

    public var sapURLSession: SAPURLSession?
  • Unique identifier created during onboarding process.

    Declaration

    Swift

    public var onboardingID: String?
  • Application specifies if UsagePolicy settings downloaded from server may be applied during onboarding.

    Declaration

    Swift

    public var enableServerOverride: Bool
  • UsageBroker property (in days) specifying frequency for uploading usage event logs.

    Declaration

    Swift

    public var uploadInterval: Int
  • Conveys server specified value of application ID and server URL as target for usage upload.

    Declaration

    Swift

    public var sapcpmsSettingsParameters: SAPcpmsSettingsParameters { get set }
  • Property used to control if UsageBroker emits usage events.

    Declaration

    Swift

    public var enableReporting: Bool { get set }
  • Initializes the UsageBroker. Typically, this is triggered in AppDelegate didFinishLaunchingWithOptions. Required call to configure OSlifecycle notification, specify data collection items during event triggers, and configure usage store behavior.

    Throws

    UsageBrokerError.usageStoreInit if UsageStore configuration fails or UsageBrokerError.reporterInit if UsageReporter instantiation fails.

    Declaration

    Swift

    public func start(OSlifecycleSessionInjection enabled: Bool = true, DataCollection items: UsageDataCollectionItems = UsageDataCollectionItems.all, retainLastUnattributedSession: Bool = true) throws

    Parameters

    enabled

    enabled: specify if os lifecycle session events and data items should be injected.

    items

    data items to collect and inject during session event processing.

    retainLastUnattributedSession

    if true, temporarily save last unattributed session in memory to inject into attributed store, else leave unattributed data in place.

  • Reinitializes the UsageBroker. Typically, this is triggered by SAPFioriFLows SAPcpmsUsagePolicyApplyStep. Specifies usage store configuration and behavior.

    The given path should be a folder path where the desired store will be created with optional encryptionKey.

    Throws

    If UsageStore configuration fails or UsageBrokerError.reporterInit if UsageReporter instantiation fails.

    Declaration

    Swift

    public func configure(path: URL = UsageStore.defaultFolderURL, storageID: UUID? = nil, encryptionKey: String? = nil, retainLastUnattributedSession: Bool = true) throws

    Parameters

    path

    store folder path

    storageID

    optional attributed basename of store (otherwise subsequent data is added to unattributed store)

    encryptionKey

    optional value (MUST remain constant after initial creation)

    retainLastUnattributedSession

    if true, temporarily save last unattributed session in memory to inject into attributed store, else leave unattributed data in place.

  • Upload Usage Log data.

    Declaration

    Swift

    public func upload(overrideInterval force: Bool = false, sapcpmsSettingsParameters: SAPcpmsSettingsParameters? = nil, sendUnattributed unattributed: Bool = true, completionHandler: @escaping (Error?) -> Void = SAPcpmsUsageUploader.defaultCompletionHandler)

    Parameters

    force

    allows ability to override interval.

    sapcpmsSettingsParameters

    optional used to specify explicit application ID and version info. for payload.

    unattributed

    also upload unattributed data even if currently configured for attributed store.

    completionHandler

    returns nil on success or error condition.