Configuring a native iOS application with the MobileFirst Platform SDK
To serve a native iOS application, MobileFirst Server must be aware of it. For this purpose, IBM MobileFirst Platform Foundation provides a Native API library, which contains a set of APIs and configuration files.
This tutorial explains how to generate the iOS Native API and how to integrate it with a native iOS application. You must generate the iOS Native API so that you can use it later on for tasks such as connecting to the MobileFirst Server instance, invoking adapter procedures, implementing authentication methods, and so on.
Prerequisite: Developers must be proficient with the Apple Xcode IDE.
Note: The Keychain Sharing capability is mandatory while running iOS apps in the iOS Simulator when using Xcode 8. You need to enable this capability manually before building the Xcode project.
This tutorial covers the following topics:
- Creating and Deploying a MobileFirst Native API
- Inside a MobileFirst Native API
- Configuring an iOS native application
- Configuring a Swift application
- Tutorials to follow next
Creating and Deploying a MobileFirst native API
- In the terminal with the CLI installed, create a new MobileFirst project using:
$ mfp create HelloWorldNative.
- Go to the newly created project directory:
$ cd HelloWorldNative/.
- Add a new iOS native API using
$ mfp add api iOSHelloWorld -e ios.
- Build and deploy the application using
$ mfp bd. This action is required for MobileFirst Server to recognize the application if it attempts to connect.
- In MobileFirst Studio, create a MobileFirst project and add a MobileFirst Native API.
- In the New MobileFirst Native API dialog, enter your application name and select iOS for the Environment field.
- Right-click the generated NativeAPI folder (located in
your-projects/apps/your-nativeapi-app-name) and select Run As > Deploy Native API.
This action is required for MobileFirst Server to recognize the application if it attempts to connect.
Inside a MobileFirst Native API
The MobileFirst native API contains several components:
WorklightAPIfolder is an IBM MobileFirst API library that you must copy to your native iOS project.
- You use the
application-descriptor.xmlfile to define application metadata and to configure security settings that MobileFirst Server enforces.
worklight.plistfile contains connectivity settings that a native iOS application uses. You must copy this file to your native iOS project.
- As with any MobileFirst project, you create the server configuration by modifying the files that are in the
The worklight.plist file
worklight.plist holds server configuration properties and is user-editable:
protocol– The communication protocol to MobileFirst Server, which is either
host– The hostname of the MobileFirst Server instance.
port– The port of the MobileFirst Server instance.
wlServerContext– The context root path of the application on the MobileFirst Server instance.
application id– The application ID as defined in the
application version– The application version.
environment– The target environment of the native application (“iOSnative”).
wlUid– This property is used by MTW (Mobile Test Workbench, an Eclipse plug-in), the test workbench, to identify this as a MobileFirst application.
wlPlatformVersion– The MobileFirst SDK version.
Configuring an iOS native application
- Create an Xcode project or use an existing one.
- Copy the previously-created
WorklightAPIfolder and the
worklight.plistfile from Eclipse to the root of the native project in Xcode.
- In the Xcode Build Phases section, link the following libraries in your native iOS application:
- libWorklightStaticLibProjectNative.a (found in WorklightAPI)
- sqlcipher.framework (found in WorklightAPI/Frameworks)
- In Xcode Build Settings:
- In Header Search Paths, add the following path:
- In Other Linker Flags, add
- In the Deployment section, for the iOS Deployment Target field, select a value that is greater than, or equal to, 6.0.
- In Header Search Paths, add the following path:
For more information review the "developing native applications for iOS" topic in the user documentation
Configuring a Swift application
Because Apple Swift is designed to be compatible with Objective-C, you can use the MobileFirst SDK from within an iOS Swift project, too.
- Create a Swift project and follow the same steps, as described at the beginning of the tutorial, to install the MobileFirst SDK into an iOS native application.
- After all the normal steps for an iOS application, go to Build Settings > Swift Compiler - Code Generation.
In Objective-C Bridging Header, add this path:
However, if you already have your own Bridging Header for other purposes, include the Worklight Bridging Header inside your own Bridging Header instead.
All the MobileFirst classes are now available from any of your Swift files.
XCode provides code autocompletion converted to the Swift style.
Tutorials to follow next
Now that your application contains the Native API library, you can follow the tutorials in the Native iOS development section to learn more about authentication and security, server-side development, advanced client-side development, notifications and more.▲