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? { get } -
Read-only access to InjectOSlifecycleSession property set during start method.
Declaration
Swift
private(set) public var injectOSlifecycleSession: Bool { get } -
Read-only access to DataCollectionItems property set during start method.
Declaration
Swift
private(set) public var collectionItems: UsageDataCollectionItems { get }
-
SAPURLSession required for uploading usage event logs.
Declaration
Swift
public var sapURLSession: SAPFoundation.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) throwsParameters
enabledenabled: specify if os lifecycle session events and data items should be injected.
itemsdata items to collect and inject during session event processing.
retainLastUnattributedSessionif 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) throwsParameters
pathstore folder path
storageIDoptional attributed basename of store (otherwise subsequent data is added to unattributed store)
encryptionKeyoptional value (MUST remain constant after initial creation)
retainLastUnattributedSessionif 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
forceallows ability to override interval.
sapcpmsSettingsParametersoptional used to specify explicit application ID and version info. for payload.
unattributedalso upload unattributed data even if currently configured for attributed store.
completionHandlerreturns nil on success or error condition.