Predix SDK for iOS · 2020-03-30 · Splunk. For more information on using Online API, see Using...
Transcript of Predix SDK for iOS · 2020-03-30 · Splunk. For more information on using Online API, see Using...
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 FITNESS FOR A PARTICULAR PURPOSE. ALL OTHER LIABILITY ARISING FROM RELIANCE UPON ANY INFORMATION CONTAINED HEREIN IS EXPRESSLY DISCLAIMED.
Access to and use of the software 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 IIoTapplications for Predix using iOS, macOS, tvOS, and watchOS. The overall application developmentprocess 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 ReferenceBefore 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 Serviceavailable on Predix.io. The SDK provides a simple native Swift API that converts Asset JSON requests andresponses 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 endpointand 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 UserAccount 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. Youcan simply tell the Authentication API that you want to use biometric authentication and the SDK doesthe work for you.
Privacy for User Credentials - The SDK respects user privacy and never stores the Usernames andPasswords. All tokens are secured in Apple's device Keychain and can only be accessed by the user whostored them.
For more information on using the Authentication API, see Using Authentication API to Authenticate aUser.
NoSQL Local Database API
The NoSQL Local Database API allows you to replicate and load balance your data. Following are some keyfeatures of the NoSQL Local Database API:
Document Database Management - Document management allowing you to write, retrieve, or delete adocument from a database. The central concept of the NoSQL database is the "document". The documentencapsulates and organizes data in name/value pairs; and it is identified by a system-wide uniqueidentifier (ID).
Async Interaction - Async interaction to maximize mobile device resources and UI responsiveness. ThePredixSDK Database API is largely asynchronous in nature. The API calls for most document interactionsand running queries takes a Swift completion handler closure as a parameter. The closure is called whenthe 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 andresponsiveness from their PredixSDK-based applications.
Data Replication - Easy set up for data replication and flexibility for many complex data iteration usecases. You can use the PredixSDK Database as a local data store and use it with the PredixSync service tosynchronize documents to and from a backend server and to other users. Data replication is a complextask but the Predix system makes it easy to setup and provides flexibility for many complex data iterationuse cases.
Note: As with any offline data interaction, care must be taken to determine what type of data a userneeds when offline. When designing your applications data model, it is important to consider that mobiledevices have limited storage capacity and often have limited network bandwidth. A balance must bestruck between having enough information to meet the applications use cases, and preventing anapplication 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 morerelational database-like data interactions. An index consists of a key (the data being indexed) and anoptional 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 keysare 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 NoSQLLocal Database API.
Offline API
The Offline API allows your application to access critical APIs when there is no internet connectivity. Youcan use the PredixSDK Database as a local data store, and use it with the PredixSync service tosynchronize 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 thisassociation, the SDK manages the bearer token and populates the authorization header for you. Thisallows you to focus on your application logic and relieves you from the additional stress of managing thebearer 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 Systemand some common visualization components. When used with Predix SDK for iOS, the PredixUIKit allowsyou to utilize the available data visualization components to accelerate the overall applicationdevelopment 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 seamlesslywith 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 Serviceavailable 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 Seriesdata from Swift.
• Predix SDK for iOS handles authentication with Time Series, you simply need to provide the UAAendpoint 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 BeginLearn 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 Xcode, the Swift programming language, and the Swiftcoding concepts. If you are not familiar with these technologies and concepts you may want to considerreading 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 instructionsbelow 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 App2. 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/ios.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 ProjectNavigator.
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 inObjective-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 navigateto 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 keydisplays 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 CouchbaseLitemodule 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