BrainBlocks iOS SDK
iOS SDK,用于将 BrainBlocks 集成到移动应用程序中
安装
CocoaPods
CocoaPods 是 Cocoa 项目的依赖关系管理器。您可以使用以下命令安装它:
$ gem install cocoapods
要构建 BrainBlocksKit,需要 CocoaPods 1.4+。
要使用 CocoaPods 将 BrainBlocks 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它。
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '12.0'
use_frameworks!
target '<Your Target Name>' do
pod 'BrainBlocksKit'
end
然后,运行以下命令:
$ pod install
使用方法
在您想要使用 BrainBlocks 的 ViewController 中,导入 BrainBlockKit 并实现以下代码:
import UIKit
import BrainBlocksKit
class ViewController: UIViewController, BrainBlocksDelegate {
override func viewDidLoad() {
super.viewDidLoad()
showPayment()
}
// Example Function
func showPayment() {
// payment nano amount. nano = 1 NANO/1000000
var amount: Double = 1
// payment view
let style: UIBlurEffectStyle = .light
// Payment Destination
let paymentAccount: String = "<Your Nano Payment Address Here>"
let paymentController = BBPaymentController.create()
paymentController.delegate = self
paymentController.blurStyle = style
paymentController.destinationAddress = paymentAccount
paymentController.paymentAmount = amount
paymentController.currency = .nano
paymentController.modalPresentationStyle = .fullScreen
// Launch BrainBlocks Popup Payment UI
self.present(paymentController, animated: true, completion: nil)
}
func paymentSessionUpdate(status: BBResponses, data: BBSessionObject?) {
}
func paymentComplete(object: BBVerificationObject) {
}
}
BrainBlocksKit 代理
func paymentSessionUpdate(status: BBResponses, data: BBSessionObject?)
func paymentComplete(object: BBVerificationObject)
BrainBlocksKit 验证对象
struct BBVerificationObject {
let token: String
let destination: String
let currency: String
let amount: Int
let amountRai: Int
let receivedRai: Int
let fulfilled: Bool
let sendBlock: String
let sender: String
}