iOS SDK for integrating BrainBlocks into a mobile app
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate BrainBlocks into your Xcode project using CocoaPods, specify it in your Podfile
:
platform :ios, '9.0'
use_frameworks!
target '<Your Target Name>' do
pod 'BrainBlocksKit', :git => 'https://github.com/brainblocks/brainblocks-ios-sdk.git', :tag => 'v0.0.1'
end
Then, run the following command:
$ pod install
In the ViewController that you would like to use BrainBlocks, import BrainBlockKit and implement code like the following.
import UIKit
import BrainBlocksKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
// Example Function
func showPayment() {
// payment rai amount - rai: 0.001 per 1 xrb
var amount: Int = 1
let paymentAccount: String = "<Your XRB Payment Address Here>"
// Launch BrainBlocks Popup Payment UI
BrainBlocksPayment().launchBrainBlocksPaymentView(viewController: self, paymentAmount: amount, paymentDestination: paymentAccount)
}
}
The Following functions can also be used as an alternative to the simple popup ui. Do Not use these with popup ui
// start brainblocks payment session
// saves token to BrainBlocksPayment.token
// saves payment account address to BrainBlocksPayment.account
// saves payment amount to BrainBlocksPayment.paymentAmount
// launch's brainBlocksTransferPayment() automatically
func brainBlocksStartSession(paymentAmount amount: Int, paymentDestination destination: String)
// start brainblocks transfer session for payment
// posts BrainBlocksPaymentFailed notification if failed else launches brainBlocksVerifyPayment()
func brainBlocksTransferPayment(token: String) {}
// verfiy brainblocks payment
// checks if token and amounts are corrent
// if correct, post BrainBlocksPaymentSuccess notification else
// post BrainBlocksInsufficientPayment notification
func brainBlocksVerifyPayment(token: String) {}
// cancels BrainBlocks Payment Session
func cancelBrainBlocksPaymentSession() {}
The BrainBlocks SDK uses local notifications to send events. Each of the following event observer's is optional but are needed to know when a specific event happens.
// Example BrainBlocksSessionStart notification and function
NotificationCenter.default.addObserver(self, selector: #selector(sessionStart), name: NSNotification.Name(rawValue: "BrainBlocksSessionStart"), object: nil)
@objc func sessionStart() {
print("BrainBlocks Payment Session Started")
}
// BrainBlocksSessionStartFailed notification and function
NotificationCenter.default.addObserver(self, selector: #selector(sessionStartFailed), name: NSNotification.Name(rawValue: "BrainBlocksSessionStartFailed"), object: nil)
@objc func sessionStartFailed() {
print("BrainBlocks Payment Session Failed")
}
// BrainBlocksPaymentSuccess notification and function
NotificationCenter.default.addObserver(self, selector: #selector(sessionSuccess), name: NSNotification.Name(rawValue: "BrainBlocksPaymentSuccess"), object: nil)
@objc func sessionSuccess() {
print("session success")
}
// BrainBlocksPaymentFailed notification and function
NotificationCenter.default.addObserver(self, selector: #selector(sessionFailed), name: NSNotification.Name(rawValue: "BrainBlocksPaymentFailed"), object: nil)
@objc func sessionFailed() {
print("session failed")
}
// BrainBlocksSessionCancelled notification and function
NotificationCenter.default.addObserver(self, selector: #selector(sessionCancelled), name: NSNotification.Name(rawValue: "BrainBlocksSessionCancelled"), object: nil)
@objc func sessionCancelled() {
print("session cancelled")
}
// BrainBlocksSessionTimeOut notification and function
NotificationCenter.default.addObserver(self, selector: #selector(sessionTimeOut), name: NSNotification.Name(rawValue: "BrainBlocksSessionTimeOut"), object: nil)
@objc func sessionTimeOut() {
print("session time out")
}
// BrainBlocksInsufficientPayment notification and function
NotificationCenter.default.addObserver(self, selector: #selector(insufficientPayment), name: NSNotification.Name(rawValue: "BrainBlocksInsufficientPayment"), object: nil)
@objc func insufficientPayment() {
print("session insufficient payment")
}