Skip to Content

Getting Started with the SAP Cloud Platform SDK for iOS

Overview

This blog series covers the SAP Cloud Platform SDK for iOS 2.0 SP01 which enables development of iOS native apps that make use of the features of the SAP Cloud Platform such as registration, logging, online OData, offline OData, push notification and SAP Fiori for iOS. My goal in writing this blog series is to demonstrate some of the key functionality provided by the SDK and to further my learnings with the SDK and iOS development. Please post any comments/corrections/suggestions so this content can be improved.

The SAP Cloud Platform and SDK are available as a free trial for non-productive use.

SAP provides multiple tools and SDKs to create a mobile apps. For a description of available options see SAP Cloud Platform Mobile Services Development Options.

The following are some other locations containing content on the SAP Cloud Platform SDK for iOS.
What is the SAP Cloud Platform SDK for iOS
Questions Tagged SAP Cloud Platform SDK for iOS
Blogs Tagged SAP Cloud Platform SDK for iOS

Blog posts by the chief product owner Andreas Schlosser are good sources of information such as What’s new in SAP Cloud Platform SDK for iOS 2.0 and What’s new in SAP Cloud Platform SDK for iOS 2.0 SP01.
Roadmaps for the SAP Cloud Platform are available at SAP Cloud Platform Roadmaps.

Setup

Development must occur on a Mac machine that has Xcode installed. Note, there is a dependency between the Xcode version and the SDK version.
The following steps detail how to setup the required software and create an iOS app that contains the SDK libraries. This app will be used in the following blog posts in this series.

Installing Xcode

Xcode 9.x is available for free from the Mac App Store. Note that a given version of the SDK has been tested with a specific version of Xcode.

Installing the SAP Cloud Platform SDK for iOS

Download the latest release version of SDK from the SAP Store and click on Trial Version.

Note that it is important that the SDK and Xcode versions match.

Once downloaded, double click on the dmg file which will open the dialog shown below and then drag the SAP Cloud Platform for iOS Assistant onto the Applications shortcut.

Additional installation information is available at Installing the SAP Cloud Platform SDK for iOS.

Enabling the SAP Cloud Platform, Mobile Service for Development and Operations

The following steps demonstrate how to register for a trial account on the SAP Cloud Platform and then to enable the Mobile Service for Development and Operations.

  1. Register for the Neo Trial account at SAP Cloud Platform Cockpit Trial. Note the SAP Cloud Platform is available in two environments, Neo (hosted on SAP infrastructure) and Cloud Foundry (can be hosted by Amazon, Google or Microsoft). The SAP Cloud Platform Mobile Services is currently available for trial on Neo.
  2. Once registered, click on your User ID.
  3. Under Services, find Development & Operations and enable it. Note this may take a few minutes to complete.
  4. Click on Development and Operations.
  5. Click on Go to Service to open the service.
    The Mobile Service for Development and Operations cockpit should now appear.

Configuring an App in the SAP Cloud Platform Mobile Services for Development and Operations Management Cockpit

The following steps demonstrate how to configure an application in the Mobile Services Development and Operations Management Cockpit. Specifically, the app will be configured to use basic authentication and will specify an OData URL that can provide the app with data.

  1. Click on the New button to add a new configuration for an app. Note that the trial account has a limit of five apps.
  2. Create a new app using the native template with the following id.
    com.iossdk.gs

  3. Click on the + icon to add the Sample Back End feature which will provide the data for the application. This will add a mobile destination to the app under Connectivity, removing the warning on the Connectivity feature.
    Select the Sample Back End feature.

    The Sample OData service contains a UI where the data can be reset or additional purchase and sales orders can be generated.
    Optionally, view the data directly in the browser with the Runtime Metadata URL using Chrome.For more details on OData see Appendix A: OData in Getting Started with Kapsel.
  4. Notice that under the Connectivity feature, a new destination has been added.
  5. Click on Security to configure it.
    Change the Security Configuration to Basic.

SAP Cloud Platform SDK for iOS Assistant

The Assistant app can be used to access the API documentation and export the tools of the SDK as well as generate a starter app.

  1. In the management cockpit, go to the Important Links section and click on Importing URLs directly into Assistant to configure the Assistant with the server URLs.

    Clicking on the link opens the Assistant to the settings screen and pre-fills it with the required URL’s.

    Close the configuration dialog to return to the main screen of the Assistant.
  2. The API docs can be accessed from the Assistant menu.
    Below is the API documentation for each component of the SDK.
  3. Install Tools.
    A popup appears showing where the tools will be installed.ILOData is a utility that can be used to create and test offline stores outside of an application. The proxy class generation tool is covered in the Online OData section of this blog series.
  4. Export Frameworks.

    The fat binaries are useful for development as they support both simulators and devices. The iPhoneOS is needed when publishing to the App Store.
  5. The Assistant can be used to create a starter project. The following steps demonstrate how this is done using the previously created app configuration.Click the + button to create a new project.

    Provide some of the project details.
    Select Use Existing and select the previously created app configuration.
    The OData service used is the sample back end OData service.
    Note, additional generation options for the selected destination’s proxy classes can be specified by clicking on the gear icon such as specifying a prefix should you wish to use multiple destinations that have entities with the same name.All of the optional features are enabled except Remote Notifications.
    Note, if you uncheck all the generation options, you get an empty project that contains the SAP Cloud Platform SDK for iOS libraries.After clicking Finish, an Xcode project will be created and opened.
    Xcode will ask for your password the first time it build and runs a project and requires administrator rights.

    After clicking on the run icon, the app can be viewed on the simulator.

    Note that the data can be modified and if needed using the management cockpit, the sample back end data can be reset.

    For another example of using the Assistant to create a sample project see the following video and Creating an app using the SAP Cloud Platform SDK for iOS Assistant.Note, we will be creating everything from scratch in the guide. This project will not be used further other than for reference.

Creating and Debugging an Xcode Project

The following steps demonstrate how to create a new project that will be used in the subsequent sections of this guide. The app will contain a button that when pressed, updates a variable numberOfPresses and prints the value to the All Output screen in Xcode. A breakpoint will then be set and using the LLDB debugger, a method will be called on the variable numberOfPresses to change its sign. For further details see Debugging Tools.

  1. In Xcode choose File, New Project.  Choose iOS, Single View App and click Next.

    Fill in the Project Name, your Organization Name, and Organization Identifier, uncheck Include Unit Tests and Include UI Tests.
    On the next screen, uncheck Create Git repository on my Mac.
  2. Drag a button onto the View.
  3. Create an action named buttonPressed of type UIButton by holding down the control key while dragging from the button to the ViewController file.
  4. Below the class definition for ViewController, add the following variable definition.
    var numberOfPresses = 0

    Then add the following code for the method buttonPressed.

    numberOfPresses = numberOfPresses + 1
    print("Button pressed \(numberOfPresses) times")
    
  5. Run the app and notice that the method buttonPressed is logging entries in the All Output view
  6. Add a breakpoint in the buttonPressed method by clicking on a line number.Then in the simulator, press the button.
  7. Notice that the breakpoint is hit and the value of the variable is shown. Also note that you can call methods on a variable. For example, execute the following lldb debugger command.
    po numberOfPresses.negate()
    po numberOfPresses

Adding the SDK Libraries to the Xcode Project

SAP Cloud Platform SDK for iOS contains functionality in libraries that can be added to Xcode projects. There are two types of libraries, ones that are specific to a simulator or device and ones that can be used in both instances (fat). The fat libraries are useful during development, but when you submit the app to the Apple App Store, you must not use fat libraries. For additional details see 3. Add the SDK to an Xcode project.

  1. Drag and drop the fat libraries into the Embedded Binaries section of your project. The libraries were previous exported using the Assistant’s Install Tools menu option.
    Choose Copy items if needed and Create groups.

    Near the top of the file ViewController.swift, below the import for UIKit, add the following import.

    import SAPFoundation
  2. In ViewController.swift, in the method buttonPressed, add the following code. ConnectivityUtils is a class from the Foundation framework of the SAP Cloud Platform SDK for iOS.
    if ConnectivityUtils.isConnected() {
        if ConnectivityUtils.isWiFiConnected() {
            print("Currently connected by WiFi")
        }
        else if ConnectivityUtils.isMobileConnected() {
            print("Currently connected by mobile data")
        }
    }
    else {
        print("Currently offline with no network connection")
    }
  3. Rerun the app, press the button, and this time in the debugger notice that the SDK class ConnectivityUtils is successfully called to determine the network state of the simulator.

Learning Swift

The SAP Cloud Platform SDK for iOS makes use of the Swift language. The following are some links that may be of interest while learning Swift and using the Interface Builder in Xcode.

Xcode Introduction
Build Swift App
A Swift Tour
Start Developing iOS Apps (Swift)
Stanford University: Developing iOS 10 Apps with Swift (iTunes U)
Intro to App Development in Swift (iBook)

Using the SAP Cloud Platform SDK

The following sections provide step by step instructions demonstrating some key features of the SAP Cloud Platform SDK for iOS.

Registration using Fiori Flows
Logging
Online Application
Offline OData
SAP Fiori for iOS

Next (Registration using Fiori Flows)

Note that comments are not easily searchable in blog posts. If you have a question that is not specific to the above content it would be best to create a new question.

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. Former Member

    Hi Dan, I’m getting an error when I try to create a new app. I fill in the information and press the Save button and I get this error:

    I’m not sure if it is related but when I go into the service I get an unknown error dialog:

    so I am unable to proceed with the tutorial. Any trouble shooting tips?

    Thanks,

    Dave

    (0) 
    1. Daniel Van Leeuwen Post author

      Is it a trial SAP Cloud Platform account?  If so, a quick workaround might be to simply register for a new trial account using a new email address.

      You might also try posting a question and use the tag SAP Cloud Platform Mobile Services.

      I have not encountered this error myself, but I imagine the way to debug it further would be to go to the Mobile Services for Development and Operations console, choose Settings > Log Settings and increase the log level of the Admin component and check the Event Logs checkbox.  Reproduce the issue and then examine the logs under Analytics > Logs.

      Hope that helps,
      Dan van Leeuwen

      (0) 
      1. Former Member

        Hi Dan, I was logged in using my SAP Partner account. I logged in with my personal trial account and didn’t encounter the error.

         

        Thanks,

        Dave

         

        (0) 

Leave a Reply