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: 
mgrasshoff
Advisor
Advisor

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:

 



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:



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

4 Comments