Predix SDK for iOS

© 2020 General Electric Company Contents

Predix SDK for iOS Overview 1 Predix SDK for iOS 1 Asset API 1 Authentication API 1 NoSQL Local Database API 2 Offline API 3 Online API 3 PredixUIKit for iOS 3 TimeSeries API 3 Getting Started with SDK for iOS 5 Before You Begin 5 Adding the SDK to Your Project 5 Adding the Module Map 6

ii Predix SDK for iOS Copyright GE Digital © 2020 General Electric Company. GE, the GE Monogram, and Predix are either registered trademarks or trademarks of General Electric Company. All other trademarks are the property of their respective owners. This document may contain Confidential/Proprietary information of General Electric Company and/or its suppliers or vendors. Distribution or reproduction is prohibited without permission. THIS DOCUMENT AND ITS CONTENTS ARE PROVIDED "AS IS," WITH NO REPRESENTATION OR WARRANTIES OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF DESIGN, MERCHANTABILITY, OR FOR A PARTICULAR PURPOSE. ALL OTHER LIABILITY ARISING FROM RELIANCE UPON ANY INFORMATION CONTAINED HEREIN IS EXPRESSLY DISCLAIMED. Access to and use of the described in this document is conditioned on acceptance of the End User License Agreement and compliance with its terms.

© 2020 General Electric Company iii

Predix SDK for iOS Overview

Predix SDK for iOS

The Predix SDK for iOS is a powerful software design kit (SDK) to accelerate the development of IIoT applications for Predix using iOS, macOS, tvOS, and watchOS. The overall application development process is simpler and faster with the use of a robust set of APIs that feel natural to a Swift developer. Predix SDK for iOS key features: • Asset API • Authentication API (UAA) • NoSQL Local Database API • Online API • Offline API • TimeSeries API For more information on the Predix SDK for iOS APIs, see the following: • Getting Started Guides • How to Guides • API Documentation Related Reference Before You Begin on page 5 Learn about prerequisites for using the Predix Mobile iOS SDK and find the SDK Download link.

Asset API

The Predix SDK for iOS Asset API allows your application to access Asset data from the Asset Service available on Predix.io. The SDK provides a simple native Swift API that converts Asset JSON requests and responses into Swift models that make it easier to use, display, and manipulate Asset data from Swift. • Predix SDK for iOS handles authentication with Asset, you simply need to provide the UAA endpoint and Zone ID. • Request data using native Swift objects. • Response data is represented with native Swift objects making it easier to filter, display, and find data that is most critical to your application. For more information on using the Asset API, see the Asset API documentation.

Authentication API

The Authentication API allows you to authenticate users and your application with the Predix User Account and Authentication (UAA). Authentication API includes: • Native authentication using User Credentials • WebView authentication using Authorization Code Grant • RefreshToken authentication using Biometrics (TouchID and FaceID) • Client Credential authentication for applications that do not use a Username and Password to protect their applications.

© 2020 General Electric Company 1 Supported iOS Features • Native UI login • UIWebView login • WKWebView login • SafariViewController login • SFAuthenticationSession Support for Biometric Authentication - The SDK works with TouchID and FaceID out of the box. You can simply tell the Authentication API that you want to use biometric authentication and the SDK does the work for you. Privacy for User Credentials - The SDK respects user privacy and never stores the Usernames and Passwords. All tokens are secured in Apple's device Keychain and can only be accessed by the user who stored them. For more information on using the Authentication API, see Using Authentication API to Authenticate a User.

NoSQL Local Database API

The NoSQL Local Database API allows you to replicate and load balance your data. Following are some key features of the NoSQL Local Database API: Document Database Management - Document management allowing you to write, retrieve, or delete a document from a database. The central concept of the NoSQL database is the "document". The document encapsulates and organizes data in name/value pairs; and it is identified by a system-wide unique identifier (ID). Async Interaction - Async interaction to maximize mobile device resources and UI responsiveness. The PredixSDK Database API is largely asynchronous in nature. The API calls for most document interactions and running queries takes a Swift completion handler closure as a parameter. The closure is called when the requested operation is complete. This is similar to many other APIs within the Apple ecosystem. Note: Developers using the PredixSDK must have a thorough understanding of asynchronous patterns, Google Cloud Datastore (GCD), and Swift closures to enable the maximum performance and responsiveness from their PredixSDK-based applications. Data Replication - Easy set up for data replication and flexibility for many complex data iteration use cases. You can use the PredixSDK Database as a local data store and use it with the PredixSync service to synchronize documents to and from a backend server and to other users. Data replication is a complex task but the Predix system makes it easy to setup and provides flexibility for many complex data iteration use cases. Note: As with any offline data interaction, care must be taken to determine what type of data a user needs when offline. When designing your applications data model, it is important to consider that mobile devices have limited storage capacity and often have limited network bandwidth. A balance must be struck between having enough information to meet the applications use cases, and preventing an application from being too “chatty” or attempting to synchronize large quantities of data. Indexes and Queries - Ability to create indexes of the documents and run queries against those indexes. With indexes and queries, you can enable searches, perform sorting, summarization, and other more relational database-like data interactions. An index consists of a key (the data being indexed) and an optional value (additional data stored with the index). The data in the index is sorted based on a key. Queries can retrieve data from the index by either specifying a list of keys or a range of keys. These keys are simple data types or arrays to provide more complex sorting and retrieval scenarios.

2 © 2020 General Electric Company For more information on using the NoSQL Local Database API, see the Getting Started with the NoSQL Local Database API.

Offline API

The Offline API allows your application to access critical APIs when there is no internet connectivity. You can use the PredixSDK Database as a local data store, and use it with the PredixSync service to synchronize documents to and from a backend server and/or to other users. • Easy to setup of data replication mechanism • Flexibility for complex data iteration use cases For more information on Offline API, see NoSQL Local Database API

Online API

The Online API allows you to associate a UAA authentication session to a network request. Based on this association, the SDK manages the bearer token and populates the authorization header for you. This allows you to focus on your application logic and relieves you from the additional stress of managing the bearer token for your network requests to Predix Services. Online API includes: • Requests to Predix services or server-side apps automatically populate the bearer token for you. • Trace IDs are automatically generated allowing you to trace and diagnose a request using tools like Splunk. For more information on using Online API, see Using the Online API to make Network Requests

PredixUIKit for iOS

The PredixUIKit for iOS is a framework of data visualization components based on Predix Design System and some common visualization components. When used with Predix SDK for iOS, the PredixUIKit allows you to utilize the available data visualization components to accelerate the overall application development process. You can use the PredixUIKit for iOS to display your data stored in Predix Cloud with very minimal coding. The Predix UI components of the PredixUIKit are open source and are built specifically to work seamlessly with the Predix SDK for iOS. PredixUIKit Features: • Data Visualization • UAA Authentication • Time Series View For more information on PredixUIKit for iOS, see the Getting Started with PredixUIKit

TimeSeries API

The TimeSeries API allows your application to access Time Series data from the Time Series Service available on Predix.io. The SDK provides a simple native Swift API that converts Time Series JSON

© 2020 General Electric Company 3 requests and responses into Swift models that make it easier to use, display, and manipulate Time Series data from Swift. • Predix SDK for iOS handles authentication with Time Series, you simply need to provide the UAA endpoint and Zone ID. • Request data using native Swift objects. • Response data is represented with native Swift objects making it easier to filter, display, and find data that is most critical to your application. For more information on using the TimeSeries API, see Using the TimeSeries API to Fetch Time Series Data

4 © 2020 General Electric Company Getting Started with SDK for iOS

Before You Begin Learn about prerequisites for using the Predix Mobile iOS SDK and find the SDK Download link.

Suggested Reading, Software Version Requirements, and Download Links This guide assumes you are comfortable using , the Swift programming language, and the Swift coding concepts. If you are not familiar with these technologies and concepts you may want to consider reading Apple's Getting Started documentation before continuing with this guide. • Read the README file • Download Xcode 9.2 or later • Download and install the latest version of Carthage • If you are behind a firewall/proxy, access GitHub from the Mac Terminal

Download the Predix Mobile iOS SDK This link takes you to the latest version of the SDK: https://github.com/PredixDev/PredixSDKForiOS/ releases/latest

Installing Carthage for SDK

About This Task Install the latest version of Carthage. You can choose to install Carthage using the installation instructions below or by downloading our GitHub repository source

Procedure 1. Open Xcode and create a new project, Single View App . File > New > Project > iOS > Single View App 2. If you haven’t already, install the latest version of Carthage. 3. Create a file named cartfile in your project. 4. Enter the following dependencies into the cartfile:

binary "https://raw.githubusercontent.com/PredixDev/PredixSDKForiOS/ master/Carthage/.json" >= 0.7

5. Run carthage update in terminal. 6. PredixSDK.framework is available at ./Carthage/Build/iOS.

Adding the SDK to Your Project

Procedure 1. Open your application's Xcode project. 2. Create a Frameworks group in your project.

© 2020 General Electric Company 5 3. Open the downloaded framework using finder (typically found in ~/Downloads/ PredixMobileSDK_iOS_vX.X.zip) or grab from the Carthage build. 4. Drag the PredixMobileSDK.framework into the Frameworks group of Xcode's Project Navigator. 5. Navigate to Project/TARGETS/targets and select the General tab in your project. 6. Scroll down to the Embedded Binaries section and add the PredixMobileSDK.framework from Frameworks group.

Related Tasks Adding the Module Map on page 6

Adding the Module Map

About This Task PredixSDKForiOS internally utilizes CouchbaseLite for syncing with the backend and it is written in Objective-C. Xcode requires a module map file so that PredixSDKForiOS can use CouchbaseLite module. Note: You must create a module.modulemap file and add it to your project. If you attempt to navigate to the ViewController.swift file and add an import for PredixSDK without adding a module. modulemap file, you will encounter the following error as soon as you build your project using the CMD + B command. Missing required module 'CouchbaseLite'

Procedure 1. Create a folder group called CouchbaseLite. 2. Create an “Empty” file in the CouchbaseLite group and name it module.modulemap . 3. Add the following content to the module.modulemap file :

module CouchbaseLite { export * }

The module.modulemap file should look like the following:

6 © 2020 General Electric Company 4. Select your project and then select the non-test target under Targets. 5. Select the Build Settings tab and search for Import Paths. 6. Locate the Swift Compiler - Search Paths section and update the Import Paths value with $ (SRCROOT)/$(PRODUCT_NAME) .

© 2020 General Electric Company 7 Note: If you have Show Setting Names enabled in the editor menu, the Setting Name of the key displays as SWIFT_INCLUDE_PATH instead of Import Paths. 7. Enter CMD+B to build the project again, compiler should be able to find the missing CouchbaseLite module by now. The following screenshot shows how the project structure after you build the project:

8 © 2020 General Electric Company Related Information https://github.com/PredixDev/PredixSDKForiOS/wiki/Using-Authentication-API-to-Authenticate-a-User

© 2020 General Electric Company 9