Unleash the Power of Mobile with Swift and the SAP Mobile Platform SDK

Attention: This is not an article about the announces SAP HANA Cloud Platform SDK for iOS, which is part of the Apple SAP partnership. This article refers to the already existing SAP Mobile Platform SDK that supports SAP Mobile Platform and SAP HANA Cloud Platform mobile service for development and operations (previously: SAP HANA Cloud Platform mobile services)

Using Apples new and modern programming language Swift can really improve developer efficiency. SAP has the SAP Mobile Platform SDK that let you consume SAP Mobile Platform or SAP HANA Cloud Platform mobile service for development and operations features, like on-boarding, push notifications, client log upload and of course it enables you to create heavy weight offline applications.

The next steps show you how you combine Apples powerful Swift language with the SAP Mobile Platform SDK and start a blank iOS project from scratch. It’s easier than you may think.

Prerequisites

Please make sure your system mets the following requirements:

Getting Started

Well, I don’t think that I need to explain much about how to install Xcode.

To install pod use this command on your Terminal

$ sudo gem install cocoapods

Try

$ pod –version

on your Terminal to validate your installation.

The SAP Mobile SDK is a download on https://www.sapstore.com/solutions/701697/SAP-Mobile-Platform

Unzip the downloaded file and

$ chmod +x installSDK.command

$ ./installSDK.command

I assume that you chose the default installation path ~/SAP/MobileSDK3.

In your Terminal navigate to your folder ~/SAP/MobileSDK3/NativeSDK.

There is a file called “NativeSDK.podspec”. This file describes the Native SDK as a dependency for cocoapod. We need to modify the file and append a bit more information. Open the file in your favorite text editor and add:

s.authors = [‘Yourname’]

s.homepage = http://www.yourwebsite.com

s.source = { :path => ‘~/SAP/MobileSDK3/NativeSDK/OdataFramework/*’}


just between the lines to the other attributes.

Save your file.

Now start XCode and create a new Swift project:

Picture1.png

Make sure you select Swift as a Language.

Well, now close the project. Serious, just close XCode.

In your Terminal navigate to your freshly create XCode project. Type

$ pod init

Now you will see a file called “Podfile”, without extension.

Open it in your favorite text editor and include the following line

$ pod ‘NativeSDK’, :path => “~/SAP/MobileSDK3/NativeSDK/”

before the closing “end” statement. Then just close the file.

This concludes the preparations, now to the last step.

Back in your project path, just type in your Terminal:

$ pod install

In your project folder the you’ll find now the file {Projectname}.xcworkspace. This is the file you will now open in Xcode and use whenever you want to work on your project.

Your project should now look like this:

Picture2.png

Your project – in my case it’s “OfflineSwiftSDK12” and it references “Pods” which holds all your NativeSDK files.

You may notice the file “OfflineSwiftSDK12-Bridging-Header.h”. This is a very important file since it defines the communication between Objective-C resources and Swift. Whenever you want to reference an object that is provided by the SAP Mobile SDK you need to specify the relevant header files. You need to create the file manually. Just go to “File” > “New” > “File…”, then choose “Header File”, name it: {PROJECTNAME}-Bridging-Header.h

This is how your bridging file could look like:

//

//  OfflineSwiftSDK12-Bridging-Header.h

//  OfflineSwiftSDK12

//

//  Created by Grasshoff, Martin on 08/06/16.

//  Copyright © 2016 Grasshoff, Martin. All rights reserved.

//

#ifndef OfflineSwiftSDK12_Bridging_Header_h

#define OfflineSwiftSDK12_Bridging_Header_h

#import “SODataOfflineStore.h”

#import “SODataOfflineStoreOptions.h”

#import “HttpConversationManager.h”

#import “UsernamePasswordProviderProtocol.h”

#import “CommonAuthenticationConfigurator.h”

#endif /* OfflineSwiftSDK12_Bridging_Header_h */

You don’t need to import all header files of the SDK, only the files which references the Objects you want to use in your code.

The last step is to tell your build that it should use the bridging header. Select your project in the project inspector, select your Target and finally select your “Build Settings”. Now scroll down in the list until you find the section “Swift Compiler Code Generation”, here point your Objective-c bridging header property to ${SRCROOT}/OfflineSwiftSDK12-Bridging-Header.h

That’s it, now you can build your app and all the NativeSDK is at your fingertips.

Next action item for you is to actually use the SDK.

I’m looking forward to see your Swift-based projects.

Have Fun,

Martin Grasshoff

To report this post you need to login first.

4 Comments

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

  1. Daniel Endres

    Hi Martin,
    thanks for the amazing blog post.

    With the newer version of cocoapods I get some errors.


    seems like the names must be unique for debug and release.

    Did you find a solution for this?

    Thanks and best regards
    Daniel

    (0) 

Leave a Reply