Application Versioning¶
Application versioning allows administrators to mark specific app versions as inactive and therefore prohibit their use. For example, set an app version as inactive if this version contains a critical bug or crash or if the app contains outdated APIs and cannot connect to your back end anymore.
To implement app versioning, use the ApplicationVersionObserver
open class in SAPFoundation
and the ApplicationVersionStep
public class in SAPFioriFlows
.
Prerequisites¶
To enable this feature, the administrator has to turn Application Versioning on in the Security tab of the application settings in the mobile services cockpit.
Registering the ApplicationVersionObserver
to an SAPURLSession
Instance¶
The following example registers the ApplicationVersionObserver
to an SAPURLSession
instance.
let urlSession: SAPURLSession = SAPURLSession instance
let applicationVersionObserver = ApplicationVersionObserver()
urlSession.register(applicationVersionObserver)
ApplicationVersionObserver
checks for the x-app-version-inactive
response header (which is either true
or false
), denoting whether the current application version is inactive or not.
If the app is inactive, then any request for this SAPURLSession
instance will be canceled and an error is propagated.
completionHandler(.cancel(ApplicationVersioningError.inactive))
ApplicationVersionStep
simplifies working with the observer without having to write your own OnboardingStep
.
It is an OnboardingStep
that registers ApplicationVersionObserver
in the onboard and restore flows and unregisters it in the reset flow.
Use this class if you want to be notified whether an application is inactive during the onboard or restore flows.
You can manually add it to your flow or use the SAPcpmsDefaultSteps
configuration array (which contains an instance of the step).
The example below shows how to add the step to the onboard flow.
// Insert the step in the correct place
let step = ApplicationVersionStep()
onboardingSteps.append(step)
...
let flow = OnboardingFlow(flowType: .onboard, context: context, steps: onboardingSteps)
The example below shows how to use SAPcpmsDefaultSteps.configuration
.
let step = CompositeStep(steps: SAPcpmsDefaultSteps.configuration) // uses ApplicationVersionStep internally
onboardingSteps.append(step)
...
let flow = OnboardingFlow(flowType: .onboard, context: context, steps: onboardingSteps)
If the application is inactive, an ApplicationVersioningError.inactive
error is thrown, which can then be intercepted in the onboardingController(_:didFail:with:completionHandler:)
method of OnboardingControllerDelegate
.
func onboardingController(_ controller: OnboardingControlling, didFail flow: OnboardingFlow, with error: Error, completionHandler: @escaping (OnboardingErrorDisposition) -> Void) {
switch flow.flowType {
case .onboard:
onboardFailed(with: error, completionHandler: completionHandler)
...
}
}
func onboardFailed(with error: Error, completionHandler: @escaping (OnboardingErrorDisposition) -> Void) {
switch error {
// handle error here
case ApplicationVersioningError.inactive:
...
}