XYO Foundation Dev Portal
  • Guides

›SDKs

Getting Started

  • Getting Started

Updates

  • Latest Updates
  • News Archive

Changemaker Challenge

  • UC San Diego and XYO

Using our Mobile SDKs

  • SDK Guide

XYO Foundation

  • Open Source Initiative

XYO Network App

  • How To Use

Explore App

  • How To Use

Bridge

  • Bridge X

Smart Contract Apps

  • Dapploy
  • Dapper
  • SCSC Library

SDKs

  • Android SDK
  • Swift SDK
  • Node Core SDK
  • Swift Core SDK
  • Kotlin Core SDK

Tools

  • XYO Tools

SWIFT SDK

The XYO Foundation provides this source code available in our efforts to advance the understanding of the XYO Procotol and its possible uses. We continue to maintain this software in the interest of developer education. Usage of this source code is not intended for production.

Install

Include in your Podfile

    source '<https://github.com/CocoaPods/Specs.git>'
    platform :ios, '11.0'
    use_frameworks!

    target 'YourAppName' do
        pod 'sdk-xyo-swift', '1.0.17'
    end

Usage

One line is all it takes to start your node

let builder = XyoNodeBuilder().setBoundWitnessDelegate(self)

You can also configure to your specific roles.

Build an XYO Node

let builder = XYONodeBuilder()

After calling the node builder, you can start the build

let node = try builder.build()

Once you have a build, you have access to properties to help you shape your node and what you want out of it.

Client

    // select the network - examples
    let bleNetwork = node.networks["ble"] as? XyoBleNetwork
    let tcpipNetwork = node.networks["tcpip"] as? XyoTcpipNetwork

    // a flag to tell the client to automatically scan
    bleNetwork?.client.scan = true

    // a flag to tell the server to listen
    bleNetwork?.server.listen = true

You can set bridges for the tcp/ip client for bridging.

    // set local bridges for the tcpip client
    tcpipNetwork?.client.localBridges = ["public key of bridge", "public key of other bridge"]

You can set the bound witness delegate

    func boundWitness(started withDeviceId: String) {
        print("Started BW with (withDeviceId)")
    }

    func boundWitness(completed withDeviceId: String, withBoundWitness: XyoBoundWitness?) {
        print("Completed BW with (withDeviceId)")
    }

You can also set a string payload data on any node that gets passed in a bound witness

    class SomeViewController: UIViewController, BoundWitnessDelegate {
        ...
        if var bleClient = (xyoNode?.networks["ble"] as? XyoBleNetwork)?.client {
          bleClient.pollingInterval = 10
          bleClient.stringHeuristic = "Hi I'm Client"
        }
        
        if var bleServer = (xyoNode?.networks["ble"] as? XyoBleNetwork)?.server {
          bleServer.stringHeuristic = "Yo I'm Server"
        }
    }

The following extensions can be used to pull data from a bound witness. Party index 0 is the server, party 1 is the client.

Payload parsing

Given the above example of passing strings, you can resolve those strings for client/server using:

    if let resolveStr = withBoundWitness?.resolveString(forParty: 0) {
      dataStr += "Server: " + resolveStr
    }
    if let resolveStr1 = withBoundWitness?.resolveString(forParty: 1) {
      dataStr += " Client: " + resolveStr1
    }

You can get all heuristics in a dictionary for a given bound witness

 extension XyoBoundWitness {
    func allHeuristics() : [String:String] {
      return XyoHumanHeuristics.getAllHeuristics(self)
    }
 }

You can also try particular heuristic resolvers with the data you get, whether they are pre-made GPS, RSSI, or Time. You can also resolve heuristic data to a custom human readable form.

Time example

Bring in the time resolver

func resolveTimePayload() {
    let resolver = TimeResolver()
    XyoHumanHeuristics.resolvers[XyoSchemas.UNIX_TIME.id] = resolver
    let key = resolver.getHumanKey(partyIndex: 1)
    return XyoHumanHeuristics.getHumanHeuristics(boundWitness: self).index(forKey: key).debugDescription
}

Bring in the RSSI resolver

    func resolveRssiPayload() {
        let resolver = RssiResolver()
        XyoHumanHeuristics.resolvers[XyoSchemas.RSSI.id] = resolver
        let key = resolver.getHumanKey(partyIndex: 1)
        return XyoHumanHeuristics.getHumanHeuristics(boundWitness: self).index(forKey: key).debugDescription
    }

GPS Resolver

RSSI Resolver

Time Resolver

String Resolver

Architecture

This sdk is built on a client/server to ensure ease of understanding during development. (The client takes on "central" role, and the server the "peripheral"). This allows us to define roles with simplicity.

SDK-XYO-swift TREE

  • XyoSDK

    • mutableList <XyoNode>

      • XyoNode(storage, networks)

        • listeners
          • boundWitnessTarget
      • XyoClient, XyoServer

        • Ble

          • context
          • relayNode
          • procedureCatalog
          • autoBridge
          • acceptBridging
          • autoBoundWitness
          • scan
        • TcpIp

          • relayNode
          • procedureCatalog
          • autoBridge
          • acceptBridging
          • autoBoundWitness

Swift Sample App

Please refer to the iOS sample for an exmple implementation for bound witness and bridging.

Install

To use the sample app to measure functionality

  • Launch Xcode
  • Click on Open an existing swift Studio Project
  • Navigate to <path to the sdk-xyo-swift>/Example/ in your file explorer
  • Open the project workspace open XyoSdkExample.xcworkspace

This sample app includes client bridging and bound witnessing with a BLE server listener.

Last updated on 4/22/2020
← Android SDKNode Core SDK →
  • Install
    • Include in your Podfile
  • Usage
    • Client
  • Architecture
  • Swift Sample App
    • Install

XYO | Developers

Copyright © 2020 XYO
DocsExplore AppProtocolSource Code
Community
GitHubTwitter