* development: (23 commits) only build mac since the other targets aren't used in testing add package resolved file rename method update readme for carthage move carthage update to before_install Document SSLSecurity class update versions; use upstream starscream in podfile dep Go back to Starscream 2.1.1 Fixes Mac build Proof of concept Remove StarScream Fix documentation Don't set configs after connect Allow changing config after init but before connect. Fixes #680 Make a bunch of things public. Fixes #803 More documentation bump starscream dev update version; again work on fixing for latest version update starscream ...
Socket.IO-Client-Swift
Socket.IO-client for iOS/OS X.
Example
import SocketIO
let socket = SocketIOClient(socketURL: URL(string: "http://localhost:8080")!, config: [.log(true), .compress])
socket.on(clientEvent: .connect) {data, ack in
print("socket connected")
}
socket.on("currentAmount") {data, ack in
if let cur = data[0] as? Double {
socket.emitWithAck("canUpdate", cur).timingOut(after: 0) {data in
socket.emit("update", ["amount": cur + 2.50])
}
ack.with("Got your currentAmount", "dude")
}
}
socket.connect()
Objective-C Example
@import SocketIO;
NSURL* url = [[NSURL alloc] initWithString:@"http://localhost:8080"];
SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{@"log": @YES, @"compress": @YES}];
[socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
NSLog(@"socket connected");
}];
[socket on:@"currentAmount" callback:^(NSArray* data, SocketAckEmitter* ack) {
double cur = [[data objectAtIndex:0] floatValue];
[[socket emitWithAck:@"canUpdate" with:@[@(cur)]] timingOutAfter:0 callback:^(NSArray* data) {
[socket emit:@"update" with:@[@{@"amount": @(cur + 2.50)}]];
}];
[ack with:@[@"Got your currentAmount, ", @"dude"]];
}];
[socket connect];
Features
- Supports socket.io 2.0+ (For socket.io 1.0 use v9.x)
- Supports binary
- Supports Polling and WebSockets
- Supports TLS/SSL
- Can be used from Objective-C
FAQS
Checkout the FAQs for commonly asked questions.
Installation
Requires Swift 4/Xcode 9.x
If you need Swift 2.3 use the swift2.3 tag (Pre-Swift 4 support is no longer maintained)
If you need Swift 3.x use v11.1.3.
Swift Package Manager
Add the project as a dependency to your Package.swift:
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "YourSocketIOProject",
dependencies: [
.package(url: "https://github.com/socketio/socket.io-client-swift", .upToNextMajor(from: "12.0.0"))
]
)
Then import import SocketIO.
Carthage
Add this line to your Cartfile:
github "socketio/socket.io-client-swift" ~> 12.1.0 # Or latest version
Run carthage update --platform ios,macosx.
Add the Starscream and SocketIO frameworks to your projects and follow the usual Carthage process.
CocoaPods 1.0.0 or later
Create Podfile and add pod 'Socket.IO-Client-Swift':
use_frameworks!
target 'YourApp' do
pod 'Socket.IO-Client-Swift', '~> 12.1.0' # Or latest version
end
Install pods:
$ pod install
Import the module:
Swift:
import SocketIO
Objective-C:
@import SocketIO;
Docs
Detailed Example
A more detailed example can be found here
An example using the Swift Package Manager can be found here
License
MIT
Description
Languages
Swift
99.3%
Ruby
0.5%
Objective-C
0.2%