Skip to Content
Technical Articles
Author's profile photo Alexandre Giguere

How to successfully logout from SAP Mobile Services with SCP SDK for iOS

In this short blog post, I will show you how you can successfully logout your user when using SAP Fiori for iOS SDK.

The landing page or homepage generated by the iOS assistant is a collection view named CollectionsViewController, in real life you will probably want to replace this view controller by your own, but for now we will pretend this is our homepage and we will add a navigation bar left button named Logout.

You can add the logout button by code in the method ViewDidLoad or in the storyboard and set up your IBAction, as you prefer …

Here is an example how to do in by code in ViewDidLoad method of the CollectionsViewController

navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Logout", style: .done, target: self, action: #selector(logout))

Logout method implementation:

    @objc func logout() {
        let sessionManager = OnboardingSessionManager.shared!

        sessionManager.logout { (error) in
            DispatchQueue.main.async {
                if error == nil {
                    let applicationUIManager = OnboardingSessionManager.shared.presentationDelegate as? ApplicationUIManager
                } else {
                    // display or log error

ResetOnboarding method implementation: (add it to your AppDelegate)

    func resetOnboarding() {
        sessionManager.presentationDelegate.showSplashScreenForOnboarding(completionHandler: { _ in })

after a successful logout, we need to restart the initial on boarding process, this is as sample as presenting our initial splash screen and calling back the onboardUser method (generated by the Assistant).



Now let’s check under the hood what is going on inside the session manager logout API.

The implementation could be find on my GitHub account here. This is just 2 samples extension on SAPURLSession and OnboardingSessionManager.

Download and drop the files into your projects, adapt it if necessary.

According to the SAP documentation, you need to send a logout request (POST) to mobile services with the logout service.


  1. Retrieve the base URL (backend URL) from your on boarding session parameters
  2. Create a logout POST request
  3. Dispatch the logout request by calling the logout method on URLSession
  4. Clear URLSession cache and cookies
  5. Finally removes and invalidates the session


To conclude, adding a logout functionality is a necessary in today app to reuse your enterprise devices for on boarding another user when a device is shared or when someone left the company and you want to pass it back to others.

Usually you will put this functionality in a profile or settings dedicated view controller. I would suggest you to use the FUIButtonFormCell for it.


        let cell = tableView.dequeueReusableCell(withIdentifier: FUIButtonFormCell.reuseIdentifier, for: indexPath as IndexPath) as! FUIButtonFormCell
        cell.button.setTitle("Logout", for: .normal)
        cell.button.setTintColor(.preferredFioriColor(forStyle: .negative), for: .normal)


happy coding




Assigned Tags

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