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 theinitmust be overriden.Declaration
Swift
public required init(flow: OnboardingFlow)Parameters
flowOnboardingFlowthat contains the necessary fields (by default) -
Use this method to get the onboarding context of this session.
OnboardingInfoKey.sapcpmsSettingsParameters- the base description of the endpoint, used to createSAPURLSessionobservers and authenticators, etc.OnboardingInfoKey.authenticationURL- used to validate the network connection for the given endpoint.
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 beOnboardingInfoKey. To learn how to store a value under the customOnboardingInfoKeyin the customOnboardingStepand to retain these custom key-value pairs in theOnboardingSession, seeOnboardingSessiondocumentation.Declaration
Swift
open func onboardingContext() -> OnboardingContextReturn Value
A new instance of
OnboardingContextthat is initialized using the values associated with this session:onboardingID,persistentStoreManager,credentialStore, andpresentationDelegate. This context also contains the Info Dictionary, which is prefilled with twoOnboardingInfoKeykeys: -
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
openStoreor performing change passcode scenarios see:StoreManagerdocumentation andavailablePasscodeActionsandperformPasscodeActionmethods 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 customConfigurationTransformerwas used)Declaration
Swift
open func storeManager() throws -> StoreManagerReturn 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
completionHandlerclosure 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
deviceTokenthe device token from application:didRegisterForRemoteNotificationsWithDeviceToken delegate
completionHandlercalled 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(completionHandler: @escaping (Error?) -> Void)Parameters
completionHandlercalled 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], completionHandler: @escaping (Error?) -> Void)Parameters
userInfouserInfo parameter from the ‘didReceiveRemoteNotification’ application delegate
completionHandlercalled after the request completes; The parameter is an Error that could be nil.
-
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
completionHandlerclosure called upon completion
-
Queries user roles from the server
Declaration
Swift
public func userRoles(completionHandler: @escaping (SAPcpmsUserRoles.SAPcpmsUserInfo?, Error?) -> Void)Parameters
completionHandlerclosure called upon completion
-
Logout error enum
- noResponseData: no response data received
- invalidResponse: invalid response with given status code
Declaration
Swift
public enum LogoutError : Error -
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
completionHandlerclosure called on completion