Skip to Content
Technical Articles
Author's profile photo Kevin Muessig

Adding Multi-User support to your iOS app

In the business world most of the time we face the challenge of cost. Cost when it comes to the daily work of employees and the tools they have to work with. In the modern days, a lot of employees rely on mobile devices to get their job done. If we speak about cost a company might not want to give their staff an iPad Pro each, they probably would want employees to share one device over different work shifts for example.

Think about a shift supervisor in a manufacturing company who works an 8-hour shift tracking and documenting manufacturing of a product. After the shift ends the production continues but with another team of staff taking over. The next shift supervisor would also need an iPad for tracking and documenting the work output for their shift, but instead of having multiple devices ready for the shift supervisors, multi-user support would solve the issue.

In general, if a user changes over the span of a work day with multiple users needing to use the device to get work done, multi-user capabilities solve the issue of having multiple devices at hand.

iOS devices don’t provide multi-user support, at least not outside of the education sector, so the SAP BTP SDK for iOS team is providing you with an easy to use multi-user API available with version 6.1.

With this blog post I want to shortly introduce you to the API and its capabilities. If you want to implement the multi-user feature into your own app you can follow this amazing tutorial by Sandeep TDS.

Enable multi-user support through SAP Mobile Services

Most of the features we want to use in combination with the SAP BTP SDK for iOS get added through SAP Mobile Services. SAP Mobile Service is a middleware service on SAP BTP providing feature support for your mobile apps. Your mobile app gets backed by a cloud app configuration holding information about the app including configurations, backend connectivity as well as mobile settings for your app.

In the Mobile Settings Exchange feature you can configure the usage of multi-user support for your native iOS app through enabling Allow Upload of Pending Changes from Previous User (Enable Multiple User Mode)

SAP%20Mobile%20Services%20-%20Mobile%20Settings%20Exchange

SAP Mobile Services – Mobile Settings Exchange

Configure Trust for Upload of pending User changes

In case you want to make sure that pending changes done by a user get uploaded before another user signs into your app, you need to configure a Trust between SAP Mobile Services and SAP BTP. This is necessary in an OData Offline scenario where your users might not be connected to the internet at all time. In such a case the upload of the made changes for data will be uploaded as soon as an internet connection has established, maybe if the employee is back in the office at the end of the shift.

[…]Similarly, you must configure trust to enable upload of pending changes from previous users of mobile applications. Establishing trust is done in the SAP BTP cockpit at the subaccount level, in the Security section.
The trust configuration enables Mobile Services to generate user authentication tokens, which are required for those applications using Basic authentication or an API key, or that upload changes on behalf of another user.
– Documentation SAP Mobile Services

Handling Multi-User support in Your iOS app

Every app generated with the SAP BTP SDK for iOS Assistant comes with an AppParameters.plist file, even if you have an app, not generated with the assistant but using the SAP BTP SDK for iOS, you probably have an AppParameters.plist file as it is required by the Mobile Settings Exchange feature.

Within that file you need to add a new entry under the Root section with the key set to User Mode.

Xcode%20-%20AppParameters.plist

Xcode – AppParameters.plist

Add Multi-User Onboarding Flow

If you want to support multi-user feature you need to make sure that each user can onboard into your app. Luckily, the SAP BTP SDK for iOS APIs support multi-user onboarding out of the box by telling the OnboardingSessionManager that this app is going to be shared between users. This will cause the Onboarding Flow to change in a way to support multi-user onboarding.

public var userDidChange = false

func applicationWillEnterForeground(_: UIApplication) {
    // Triggers to show the multi-user passcode screen
    OnboardingSessionManager.shared.unlock() { error in
        guard let error = error else {
            if self.userDidChange {
                self.afterOnboard()
                self.userDidChange = false
            }
            return
        }

        self.onboardingErrorHandler?.handleUnlockingError(error)
    }
}

func initializeOnboarding() {
    let presentationDelegate = ApplicationUIManager(window: self.window!)
    self.onboardingErrorHandler = OnboardingErrorHandler()
    self.sessionManager = OnboardingSessionManager(presentationDelegate: presentationDelegate, flowProvider: self.flowProvider, onboardingIDManager: MultiUserOnboardingIDManager(), delegate: self.onboardingErrorHandler)
    presentationDelegate.showSplashScreenForOnboarding { _ in }

    self.onboardUser()
}

In the OnboardingFlowProvider you need to implement the multi-user callbacks from the FUIPasscodeControllerDelegate protocol. This protocol contains callback methods for adding new users and switching between existing users.

extension OnboardingFlowProvider: FUIPasscodeControllerDelegate {
    public func shouldTryPasscode(_ passcode: String, forInputMode inputMode: FUIPasscodeInputMode, fromController passcodeController: FUIPasscodeController) throws {
        print("Called shouldTryPasscode")
    }

    public func shouldResetPasscode(fromController passcodeController: FUIPasscodeController) {
        print("Called shouldResetPasscode")
    }


    public func addNewUser(_ passcodeController: FUIPasscodeController) {
        print("Called addNewUser")
        AppDelegate.shared.userDidChange = true
    }

    public func switchUser(_ newUserId: String, passcodeController: FUIPasscodeController) {
        print("Called switchUser")
        AppDelegate.shared.userDidChange = true
    }
}

Furthermore add the multi-user onboarding flow step to the OnboardingFlowProvider.

private func configuredStoreManagerStep() -> StoreManagerStep {
    let st = StoreManagerStep()
    st.userPasscodeControllerDelegate = self
    return st
}

public var onboardingSteps: [OnboardingStep] {
        return [
            self.configuredWelcomeScreenStep(),
            CompositeStep(steps: SAPcpmsDefaultSteps.configuration),
            OAuth2AuthenticationStep(),
            CompositeStep(steps: SAPcpmsDefaultSteps.settingsDownload),
            CompositeStep(steps: SAPcpmsDefaultSteps.applyDuringOnboard),
            self.configuredUserConsentStep(),
            self.configuredDataCollectionConsentStep(),
            configuredStoreManagerStep(),
            ODataOnboardingStep(),
        ]
    }

    public var restoringSteps: [OnboardingStep] {
        return [
            configuredStoreManagerStep(),
            self.configuredWelcomeScreenStep(),
            CompositeStep(steps: SAPcpmsDefaultSteps.configuration),
            OAuth2AuthenticationStep(),
            CompositeStep(steps: SAPcpmsDefaultSteps.settingsDownload),
            CompositeStep(steps: SAPcpmsDefaultSteps.applyDuringRestore),
            self.configuredDataCollectionConsentStep(),
            ODataOnboardingStep(),
        ]
    }

Conclusion

As you can see using the SAP BTP SDK for iOS to implement the multi-user feature into your app is pretty straightforward. Using the feature enables your customers and/or employees to use one device and have the capability to just hand it over to a peer for further work.

Handling of errors and implementing an offline scenario can be found in the tutorial mentioned above and I would highly encourage going through the tutorial to get hands-on experience with this feature.

Let me know what you think in the comment section below!

 

Happy Coding and Have a nice Weekend!

 

Assigned tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.