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
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")
]
)
If you prefer not to use either of the aforementioned dependency managers, you can integrate Spreadbot_iOS into your project manually.
cd
into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:$ git init
$ 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.
+
button under the "Embedded Binaries" section.Spreadbot_iOS.framework
.
// 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()
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.
Available as a property on an instance of the Spreadbot class
state
connecting
connected
disconnected
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)
- watchOS, macOS (OS X) and tvOS
- Linux support
- Add more tests
- SSL support
- Custom queues?
Spreadbot_iOS by Spreadbot.io makes use of the following libraries:
Spreadbot_iOS is released under the MIT license. See LICENSE for details.