iOS SDK Setup
1. Prerequisite
You will need to integrate server side SDK on your server. You can use one of the available server side SDKs: PHP, Ruby, Java, Node.js.
2. Requirements
iOS version: 9.0 and above
Recommended iOS version: 10.3
Swift version: 4.2
3. Install iOS Wallet SDK
Carthage
A). Installing iOS Wallet SDK usingCarthage
i). InstallingGet Carthage by running the following command on terminal
brew install carthage
You can also choose other methods to install Carthage
ii). Downloading wallet SDK using Carthage
Carthage looks at a file called Cartfile
to determine which libraries to install. Create a file in the same directory as your Xcode project called Cartfile
and enter the following to tell Carthage which dependencies we want:
Add following entry in your Cartfile
github "ostdotcom/ost-wallet-sdk-ios"
Now to actually install everything run the following in your terminal:
carthage update --platform iOS
A Cartfile.resolved
file and a Carthage
directory will appear in the same directory where your .xcodeproj
or .xcworkspace
is.
OstWalletSdk.framework
file in your Xcode project
iii). Copying the Open your project in Xcode, click on the project file in the left section of the screen and scroll down to the Linked Frameworks and Libraries
section in Xcode.
Carthage
folder will have the .framework
files that we will add in Xcode project.
Now open the Carthage/Build/iOS
folder in Finder:
Run this command
open Carthage/Build/iOS
Open application target, under General tab, drag the built OstWalletSdk.framework
binary from Carthage/Build/iOS
folder into Linked Frameworks and Libraries section.
OstWalletSdk
dependencies in your Xcode project
iv). Adding the We need to add the .framework
files of dependencies present inside Carthage/Build/iOS
.
Open application targets
in Xcode. Under Build Phases
click +
icon and choose New Run Script Phase
. Add the following command.
/usr/local/bin/carthage copy-frameworks
Click the +
under Input Files
and add the following entry framework:
$(SRCROOT)/Carthage/Build/iOS/Alamofire.framework
$(SRCROOT)/Carthage/Build/iOS/BigInt.framework
$(SRCROOT)/Carthage/Build/iOS/CryptoEthereumSwift.framework
$(SRCROOT)/Carthage/Build/iOS/CryptoSwift.framework
$(SRCROOT)/Carthage/Build/iOS/EthereumKit.framework
$(SRCROOT)/Carthage/Build/iOS/FMDB.framework
$(SRCROOT)/Carthage/Build/iOS/SipHash.framework
$(SRCROOT)/Carthage/Build/iOS/OstWalletSdk.framework
v). Adding SDK configuration file
Create OstWalletSdk.plist
file. This file has configuration attributes used by OstWalletSdk. You should copy paste the configuration values from below snippet.
Copy paste this configuration file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BlockGenerationTime</key>
<integer>3</integer>
<key>PricePointTokenSymbol</key>
<string>OST</string>
<key>PricePointCurrencySymbol</key>
<string>USD</string>
<key>RequestTimeoutDuration</key>
<integer>30</integer>
<key>PinMaxRetryCount</key>
<integer>3</integer>
<key>SessionBufferTime</key>
<integer>3600</integer>
<key>UseSeedPassword</key>
<false/>
</dict>
</plist>
- BlockGenerationTime: The time in seconds it takes to mine a block on auxiliary chain.
- PricePointTokenSymbol: This is the symbol of base currency. So its value will be
OST
. - PricePointCurrencySymbol: It is the symbol of quote currency used in price conversion.
- RequestTimeoutDuration: Request timeout in seconds for https calls made by ostWalletSdk.
- PinMaxRetryCount: Maximum retry count to get the wallet Pin from user.
- SessionBufferTime: Buffer expiration time for session keys in seconds.
- UseSeedPassword: Uses mnemonics and password to generate seed.
These configurations are MANDATORY for successful operation. Failing to set them will significantly impact usage.
NSFaceIDUsageDescription
description in info.plist
vi). Add The iOS Wallet SDK can use FaceID in lieu of fingerprint if the hardware supports it. To support faceID, please include NSFaceIDUsageDescription key in your application's info.plist
file and describe its usage.
Note: NSFaceIDUsageDescription key is supported in iOS 11 and later.
4. Initialize the wallet SDK
SDK initialization should happen before calling any other workflow
. To initialize the SDK, we need to call init
workflow of wallet SDK. It initializes all the required instances and run db migrations.
Recommended location to call OstWalletSdk.initialize() is in application method of UIApplicationDelegate.
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
do {
try OstWalletSdk.init(apiEndPoint: <OST_PLATFORM_API_ENDPOINT>)
} catch let ostError {
// Handle error here
}
return true
}
OST_PLATFORM_API_ENDPOINT: This will be the base API URL we need to provide to SDK while initializing.
Sandbox mode endpoint: "api.ost.com/testnet/v2"
Production endpoint: "api.ost.com/mainnet/v2"
5. Setting up communication between app and wallet SDK
iOS Wallet SDK provides workflows
that can be called by any controller class to perform wallet related actions. Communication between app and wallet SDK happens through callback functions. We need to pass the callback functions in workflows
provided by SDK. The group of callback functions for communication between app and wallet SDK is provided in OstWorkflowDelegate
protocol.
OstWorkflowDelegate
protocol
a). Implementing the There are different ways to implement OstWorkflowDelegate
and pass them while calling workflows. We will create a dedicated class with name OstWalletSdkInteract
. This class will implement the OstWorkflowDelegate
protocol. We will use this class to create object that can be passed in SDK workflows as callback.
Sample Implementation of OstWalletSdkInteract class is available as a part of demo app .
import Foundation
import OstWalletSdk
import MaterialComponents
class OstWalletSdkInteract: BaseModel, OstWorkFlowCallbackProtocol {
extension OstWalletSdkInteract {
func flowComplete(workflowContext: OstWorkflowContext, ostContextEntity: OstContextEntity) {
var eventData:[String: Any] = [:];
eventData["eventType"] = WorkflowEventType.flowComplete;
eventData["workflowContext"] = workflowContext;
eventData["ostContextEntity"] = ostContextEntity;
self.fireEvent(eventData: eventData);
}
func flowInterrupted(workflowContext: OstWorkflowContext, error: OstError) {
var eventData:[String: Any] = [:];
eventData["eventType"] = WorkflowEventType.flowInterrupt;
eventData["workflow"] = workflowContext.workflowType;
eventData["workflowContext"] = workflowContext;
eventData["ostError"] = error;
self.fireEvent(eventData: eventData);
}
// more functions here
.....
.....
}
OstWalletSdkInteract
class
b). Using OstWalletSdkInteract
can be used to create object that can be passed as callback in workflows.
Example
In the example below, we are calling OstWalletSdk.addSession
workflow and passing object of OstWalletSdkInteract
class
var sdkInteract: OstWalletSdkInteract = {
let interact = OstWalletSdkInteract();
return interact;
}()
OstWalletSdk.addSession(
userId: currentUser.ostUserId!,
spendingLimit: self.spendingLimitTestField.text!,
expireAfter: Double(expireAfter),
delegate: self.sdkInteract)
Sample code showing above example in detail is available on github.
Demo App
To provide developers with sample integration of wallet SDK, a demo iOS app is available on github.
Next Steps
- Create Wallet Guide
- Execute Transaction Guide
- iOS Wallet SDK Methods, Protocol and Classes