Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Dan_vL
Product and Topic Expert
Product and Topic Expert

Table of Contents


Overview
Setup
Installing Xcode
Installing the SAP Cloud Platform SDK for iOS
Enabling SAP Cloud Platform Mobile Services
Configuring an App in the SAP Cloud Platform Mobile Services Cockpit
SAP Cloud Platform SDK for iOS Assistant
Creating and Debugging an Xcode Project
Adding the SDK Libraries to the Xcode Project
Learning Swift
Using the SAP Cloud Platform SDK
Registration using Fiori Flows
Logging
Online OData
Offline OData
SAP Fiori for iOS

Overview


This blog series covers the SAP Cloud Platform SDK for iOS 3.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 mobile apps. For a description of available options see SAP Cloud Platform Mobile Services Development Options and SAP Cloud Platform SDK for Android.

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 3.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 10 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 the 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 SAP Cloud Platform Mobile Services


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

  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 Mobile Services and enable it. Note this may take a few minutes to complete.

  4. Click on Mobile Services.

  5. Click on Go to Service to open the service.
    The Mobile Services  cockpit should now appear.


Configuring an App in the SAP Cloud Platform Mobile Services Cockpit


The following steps demonstrate how to configure an application in the Mobile Services  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 were 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 Create new button to create a new project.
    Select Reuse as the configuration has already been created in the Mobile Services Cockpit.
    Select Use the previously created account.


    Select the previously created application configuration.


    Provide some of the project details.


    The OData service used is the sample back end OData service.
    Additional generation options for a destination's proxy classes can be specified by hovering over the destination and choosing edit. One option is to specify a prefix should you wish to use multiple destinations that have entities with the same name.


    The final page enables the selection of which destination to use for the generated screens or if an empty project should be generated.  If you choose Single View, an empty project that contains the SAP Cloud Platform SDK for iOS libraries and the proxy classes to access the destination will be created.


    Note that the features such as push, log upload, offline and the discovery service are all enabled or disabled based on the application configuration specified in the Mobile Services Cockpit. To see these options, when choosing to create new in the assistant, choose create a new application instead of reuse.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.
13 Comments