Coder Social home page Coder Social logo

brainblocks-ios-sdk's Introduction

brainblocks-ios-sdk

iOS SDK for integrating BrainBlocks into a mobile app

demo

Installation

CocoaPods

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

Usage

Recommend Method

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)
    }
 }

Alternative Method

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() {}

BrainBlocks SDK Events

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.

BrainBlocksSessionStart notification

// 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

// 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

// 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

// 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

// 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

// 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

// 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")
}

brainblocks-ios-sdk's People

Contributors

schenkty avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.