OnboardingSession

open class OnboardingSession

Stores information about an onboarding session Application developer can subclass OnboardingSession to add other app related meaningful properties or to set properties properly. For example when the SAPcpmsSettingsParameters is not stored using the default key in OnboardingContext then subclasses have to implement the code to provide the SAPcpmsSettingsParameters based on the used key

open class YourSession: OnboardingSession {
    var appURL: URL!
    var otherIntProperty: Int = 0
    var appDict = [String: Any]()

    required public init(flow: OnboardingFlow) {
       super.init(flow: flow)

        // When SAPcpmsSettingsParameters is under another key
        self.settingsParameters = flow.context.info[.yourSettingsParameters] as? SAPcpmsSettingsParameters

        self.appURL = URL(string:"")
        self.otherIntProperty = 12
        self.appDict = ["a":"b"]
    }
}

When a custom OnboardingInfoKey needs to be used to store a custom value, then the corresponding OnboardingSession subclass may be implemented as follows:

public extension OnboardingInfoKey {
    static let yourCustomOnboardingInfoKey = OnboardingInfoKey("yourCustomOnboardingInfoKey")
}

class CustomOnboardingStep: OnboardingStep{
     func onboard(context: OnboardingContext, completionHandler: @escaping (OnboardingResult) -> Void) {
         var newContext = context

         // set value under newly added key inside Info dictionary
         newContext.info[.yourCustomOnboardingInfoKey] = "AnyStringValue"

         completionHandler(.success(newContext))
     }

     func restore(context: OnboardingContext, completionHandler: @escaping (OnboardingResult) -> Void) {
         var newContext = context

         // set value under newly added key inside Info Dictionary
         newContext.info[.yourCustomOnboardingInfoKey] = "AnyStringValue"

         completionHandler(.success(newContext))
     }

     func reset(context: OnboardingContext, completionHandler: @escaping () -> Void) {
         completionHandler()
     }

}

open class YourSession: OnboardingSession {

    var yourCustomProperty: Any = ""

    required public init(flow: OnboardingFlow) {
        super.init(flow: flow)

        // set value of custom property here
        yourCustomProperty = flow.context.info[.yourCustomOnboardingInfoKey]
    }
}

//Use the code below to access it
OnboardingSessionManager.shared.onboardingSession?.yourCustomProperty
  • Onboarding ID

    Declaration

    Swift

    public let onboardingID: UUID
  • Authentication URL

    Declaration

    Swift

    public let authenticationURL: URL?
  • Credentials Store

    Declaration

    Swift

    public let credentialStore: CompositeCodableStoring
  • SAPURLSession

    Declaration

    Swift

    public let sapURLSession: SAPURLSession
  • SettingsParameters

    Declaration

    Swift

    public let settingsParameters: SAPcpmsSettingsParameters?
  • Type of flow

    Declaration

    Swift

    public let flowType: OnboardingFlow.FlowType
  • Presentation Delegate

    Declaration

    Swift

    public let presentationDelegate: FlowPresentationDelegate
  • Initializer If customs OnboardingInfoKeys are being used, then the init must be overriden.

    Declaration

    Swift

    public required init(flow: OnboardingFlow)

    Parameters

    flow

    OnboardingFlow that contains the necessary fields (by default)

  • Use this method to get the onboarding context of this session.

    No custom onboarding key-value pairs will be presented in the Info Dictionary. However, you can add a custom key-value pair as a new entry using a custom OnboardingStep, where the key type must be OnboardingInfoKey. To learn how to store a value under the custom OnboardingInfoKey in the custom OnboardingStep and to retain these custom key-value pairs in the OnboardingSession, see OnboardingSession documentation.

    Declaration

    Swift

    open func onboardingContext() -> OnboardingContext

    Return Value

    A new instance of OnboardingContext that is initialized using the values associated with this session: onboardingID, persistentStoreManager, credentialStore, and presentationDelegate. This context also contains the Info Dictionary, which is prefilled with two OnboardingInfoKey keys:

  • Invalidates the OnboardingSession. After this method has been called, the SAPURLSession, the CredentialStore and other fields cannot be used - behavior is undefined if used

    Declaration

    Swift

    open func invalidate()
  • Creates a new instance of a properly configured store manager which can be used to perform ‘unlock’ functionality by calling openStore or performing change passcode scenarios see: StoreManager documentation and availablePasscodeActions and performPasscodeAction methods The default implementation uses the default values of the StoreManager and the SAPcpmsSettingsDownloadStep to load the FUIPAsscodePolicy. This method must be overriden * If the StoreManager’s defaultPasscodePolicy was changed * the policy was downloaded on other ways * the policy is stored under custom key (for example a custom ConfigurationTransformer was used)

    Declaration

    Swift

    open func storeManager() throws -> StoreManager

    Return Value

    Configured StoreManager instance swift // using store manager and setting the default passcode policy to nil open override func storeManager() throws -> StoreManager { let storeManager = try super.storeManager() storeManager.defaultPasscodePolicy = nil return storeManager }

  • Upload Logs

    Declaration

    Swift

    public func uploadLogs(completionHandler: @escaping (Error?) -> Void = SAPcpmsLogUploader.defaultCompletionHandler)

    Parameters

    completionHandler

    closure called upon completion

  • Upload the device token to the server

    Declaration

    Swift

    public func registerDeviceToken(deviceToken: Data, withParameters parameters: SAPcpmsRemoteNotificationParameters?, completionHandler: @escaping (Error?) -> Void)

    Parameters

    deviceToken

    the device token from application:didRegisterForRemoteNotificationsWithDeviceToken delegate

    completionHandler

    called after the request completes; The parameter is an Error that could be nil.

  • Upload the device token to the server

    Declaration

    Swift

    public func registerDeviceToken(deviceToken: Data, withParameters parameters: SAPcpmsRemoteNotificationParameters?) async throws

    Parameters

    deviceToken

    the device token from application:didRegisterForRemoteNotificationsWithDeviceToken delegate

  • Unregister the existing device token from the server

    Declaration

    Swift

    public func unregisterDeviceToken(completionHandler: @escaping (Error?) -> Void)

    Parameters

    completionHandler

    called after the request completes; The parameter is an Error that could be nil.

  • Unregister the existing device token from the server

    Declaration

    Swift

    public func unregisterDeviceToken() async throws
  • Provide information about the notification status. This adjusts the notification status to ‘consumed’ on SAP Mobile Services Cockpit Reporting menu.

    Declaration

    Swift

    public func updateNotificationStatus(userInfo: [AnyHashable : Any], completionHandler: @escaping (Error?) -> Void)

    Parameters

    userInfo

    userInfo parameter from the ‘didReceiveRemoteNotification’ application delegate

    completionHandler

    called after the request completes; The parameter is an Error that could be nil.

  • Provide information about the notification status. This adjusts the notification status to ‘consumed’ on SAP Mobile Services Cockpit Reporting menu.

    Declaration

    Swift

    public func updateNotificationStatus(userInfo: [AnyHashable : Any]) async throws

    Parameters

    userInfo

    userInfo parameter from the ‘didReceiveRemoteNotification’ application delegate

  • Get list of all active topic subscriptions

    Throws

    error in case of failure

    Declaration

    Swift

    public func getAllSubscribedTopics() async throws -> [String]

    Return Value

    an array of subscribed topics if available

  • Subscribe to the topic that is passed as parameter

    Throws

    error in case of failure

    Declaration

    Swift

    public func subscribe(to topic: String) async throws

    Parameters

    topic

    a string value to subscribe

  • Unsubscribe from the topic that is passed as parameter

    Throws

    error in case of failure

    Declaration

    Swift

    public func unsubscribe(from topic: String) async throws

    Parameters

    topic

    a string value to unsubscribe from

  • Collects the usage records for the given target identifier, and uploads them in the SAPcpms format to the given endpoint. After the upload a new session should be started.

    Declaration

    Swift

    public func uploadUsageData(completionHandler: @escaping (Error?) -> Void = SAPcpmsUsageUploader.defaultCompletionHandler)

    Parameters

    completionHandler

    closure called upon completion

  • Queries user roles from the server

    Declaration

    Swift

    public func userRoles(completionHandler: @escaping (SAPcpmsUserRoles.SAPcpmsUserInfo?, Error?) -> Void)

    Parameters

    completionHandler

    closure called upon completion

  • Logout error enum

    • noResponseData: no response data received
    • invalidResponse: invalid response with given status code
    See more

    Declaration

    Swift

    public enum LogoutError : Error
  • Logs out the user on the server (invalidating the authentication tokens)

    You may use this function during a failing onboarding flow in which the user is already authenticated

    Declaration

    Swift

    public static func logout(sapURLSession: SAPURLSession, settingsParameters: SAPcpmsSettingsParameters, completionHandler: @escaping (Error?) -> Void)

    Parameters

    sapURLSession

    with a registered observer to provide the required authentication token

    settingsParameters

    to identify to which backendURL the logout request shall be send

    completionHandler

    closure called on completion

  • Logs out the user on the server (invalidating the authentication tokens)

    You may use this function during a failing onboarding flow in which the user is already authenticated

    Declaration

    Swift

    public static func logout(sapURLSession: SAPURLSession, settingsParameters: SAPcpmsSettingsParameters) async throws

    Parameters

    sapURLSession

    with a registered observer to provide the required authentication token

    settingsParameters

    to identify to which backendURL the logout request shall be send

  • Logs out the user on the server (invalidating the authentication tokens) Does not invalidate the OnboardingSession! The next requst should trigger an authentication automatically

    Declaration

    Swift

    public func logout(completionHandler: @escaping (Error?) -> Void)

    Parameters

    completionHandler

    closure called on completion

  • Logs out the user on the server (invalidating the authentication tokens) Does not invalidate the OnboardingSession! The next requst should trigger an authentication automatically

    Declaration

    Swift

    public func logout() async throws