Spreadbot_iOS 1.1.0

Spreadbot_iOS 1.1.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Aug 2017
SwiftSwift Version 3.1
SPMSupports SPM

Maintained by Spreadbot.



 
Depends on:
Alamofire~> 4.5
Starscream~> 2.1
 

Spreadbot client for iOS

Requirements

  • iOS 9.0+
  • Xcode 8.0+
  • Swift 3.0+

Installation

Swift Package Manager

To use Spreadbot_iOS as a Swift Package Manager package just add the following in your Package.swift file.

import PackageDescription

let package = Package(
    name: "HelloSpreadbot_iOS",
    dependencies: [
        .Package(url: "https://github.com/Spreadbot/Spreadbot_iOS.git", "1.0.9")
    ]
)

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate Spreadbot_iOS into your project manually.

Git Submodules

  • Open up Terminal, cd into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:
$ git init
  • Add Spreadbot_iOS as a git submodule by running the following command:
$ git submodule add https://github.com/Spreadbot/Spreadbot_iOS.git
$ git submodule update --init --recursive
  • Open the new Spreadbot_iOS folder, and drag the Spreadbot_iOS.xcodeproj into the Project Navigator of your application's Xcode project.

    It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.

  • Select the Spreadbot_iOS.xcodeproj in the Project Navigator and verify the deployment target matches that of your application target.

  • Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.

  • In the tab bar at the top of that window, open the "General" panel.

  • Click on the + button under the "Embedded Binaries" section.

  • You will see two different Spreadbot_iOS.xcodeproj folders each with two different versions of the Spreadbot_iOS.framework nested inside a Products folder.

    It does not matter which Products folder you choose from.

  • Select the Spreadbot_iOS.framework.

  • And that's it!

The Spreadbot_iOS.framework is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.

Embeded Binaries

  • Download the latest release from https://github.com/Spreadbot/Spreadbot_iOS/releases
  • Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
  • In the tab bar at the top of that window, open the "General" panel.
  • Click on the + button under the "Embedded Binaries" section.
  • Add the downloaded Spreadbot_iOS.framework.
  • And that's it!

Usage

Spreadbot API

// Import 
import Spreadbot_iOS

// Setup and configuration
let spreadbot: Spreadbot = Spreadbot(config: [
		"baseURL": "http://wwww.my-spreadbot-server.com",
		"authURL": "http://wwww.my-spreadbot-auth-server.com",
		"accessToken": "myAccessToken",
		"refreshToken": "myRefreshToken",
		"base64Credentials": "MyBase64Credentials",
		"log": true // should be false in production
	])

// Connect and subscribe to a path
spreadbot.establishConnection(path: "myPath")
   
spreadbot.onOpen {
  // When a connection has been opened
}
        
spreadbot.onError { (error) in
  // When a connection error has occured
}

spreadbot.onMessage { (id, event, data) in
  	// id: iteration
	// event: path
	// data: data
}

// Send string message
spreadbot.sendMessageString(message: "myMessage")

// Send binary message
spreadbot.sendMessageBinary(message: data)
   
// Disconnect   
spreadbot.closeConnection()

Reconnection

Sever Side Events (SSE) are used as a fallback if a Websocket connection cannot be established.

In turn, HTTP long polling will be attempted if a SSE connection cannot be established, polling every 15 seconds for new data.

If a Websocket connection is not established, a POST request will be attempted to send the data. Up-to 100 requests will be queued in the event of no internet connection.

All connection types will attempt to reconnect up-to 3 times in the event of a unexpected network disconnection.

If a connection is dropped due to the newtwork becomming unreachable then the Spreadbot library will wait till the newtwork becomes reachable again before attemtping to reconnect.

State

Available as a property on an instance of the Spreadbot class

  • state
    • connecting
    • connected
    • disconnected

SpreadbotREST API

  • Requests are asynchronous
  • Responses are handled on the main thread
  • 5 second timeout limit applies
  • Up-to a maximum of 100 network requests will be queued in the event of a loss of network connection
  • Up-to 3 attempts will be made to get a response with an exponential delay between each retry request

GET

// Import 
import Spreadbot_iOS

// Setup and configuration
let spreadbotREST: SpreadbotREST = SpreadbotREST(config: [
		"baseURL": "http://wwww.my-spreadbot-server.com",
		"authURL": "http://wwww.my-spreadbot-auth-server.com",
		"accessToken": "myAccessToken",
		"refreshToken": "myRefreshToken",
		"base64Credentials": "MyBase64Credentials",
		"log": true // should be false in production
	])

spreadbotREST
	.getData(path: String, onSuccess: @escaping (Any) -> Void, onError: @escaping (Error) -> Void)

POST

let spreadbotREST: SpreadbotREST = SpreadbotREST(config: [
		"baseURL": "http://wwww.my-spreadbot-server.com",
		"authURL": "http://wwww.my-spreadbot-auth-server.com",
		"accessToken": "myAccessToken",
		"refreshToken": "myRefreshToken",
		"base64Credentials": "MyBase64Credentials",
		"log": true // should be false in production
	])

spreadbotREST
	.postData(path: String, payload: Data, onSuccess: @escaping (Any) -> Void, onError: @escaping (Error) -> Void)

ToDo

- watchOS, macOS (OS X) and tvOS
- Linux support
- Add more tests
- SSL support
- Custom queues?

Credits

Spreadbot_iOS by Spreadbot.io makes use of the following libraries:

License

Spreadbot_iOS is released under the MIT license. See LICENSE for details.