Update README.md

This commit is contained in:
Håvard Fossli 2017-04-04 11:03:42 +02:00 committed by GitHub
parent 1949b1fd48
commit 9a2b59ad78

View File

@ -1,9 +1,9 @@
[![Build Status](https://travis-ci.org/socketio/socket.io-client-swift.svg?branch=master)](https://travis-ci.org/socketio/socket.io-client-swift) [![Build Status](https://travis-ci.org/socketio/socket.io-client-swift.svg?branch=master)](https://travis-ci.org/socketio/socket.io-client-swift)
#Socket.IO-Client-Swift # Socket.IO-Client-Swift
Socket.IO-client for iOS/OS X. Socket.IO-client for iOS/OS X.
##Example ## Example
```swift ```swift
import SocketIO import SocketIO
@ -26,7 +26,7 @@ socket.on("currentAmount") {data, ack in
socket.connect() socket.connect()
``` ```
##Objective-C Example ## Objective-C Example
```objective-c ```objective-c
@import SocketIO; @import SocketIO;
NSURL* url = [[NSURL alloc] initWithString:@"http://localhost:8080"]; NSURL* url = [[NSURL alloc] initWithString:@"http://localhost:8080"];
@ -50,14 +50,14 @@ SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{
``` ```
##Features ## Features
- Supports socket.io 1.0+ - Supports socket.io 1.0+
- Supports binary - Supports binary
- Supports Polling and WebSockets - Supports Polling and WebSockets
- Supports TLS/SSL - Supports TLS/SSL
- Can be used from Objective-C - Can be used from Objective-C
##Installation ## Installation
Requires Swift 3/Xcode 8.x Requires Swift 3/Xcode 8.x
If you need swift 2.3 use the swift2.3 tag (Pre-Swift 3 support is no longer maintained) If you need swift 2.3 use the swift2.3 tag (Pre-Swift 3 support is no longer maintained)
@ -70,13 +70,11 @@ If you need Swift 1.2 use v2.4.5 (Pre-Swift 2 support is no longer maintained)
If you need Swift 1.1 use v1.5.2. (Pre-Swift 1.2 support is no longer maintained) If you need Swift 1.1 use v1.5.2. (Pre-Swift 1.2 support is no longer maintained)
Manually (iOS 7+) ### Manually (iOS 7+)
-----------------
1. Copy the Source folder into your Xcode project. (Make sure you add the files to your target(s)) 1. Copy the Source folder into your Xcode project. (Make sure you add the files to your target(s))
2. If you plan on using this from Objective-C, read [this](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html) on exposing Swift code to Objective-C. 2. If you plan on using this from Objective-C, read [this](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html) on exposing Swift code to Objective-C.
Swift Package Manager ### Swift Package Manager
---------------------
Add the project as a dependency to your Package.swift: Add the project as a dependency to your Package.swift:
```swift ```swift
import PackageDescription import PackageDescription
@ -91,8 +89,7 @@ let package = Package(
Then import `import SocketIO`. Then import `import SocketIO`.
Carthage ### Carthage
-----------------
Add this line to your `Cartfile`: Add this line to your `Cartfile`:
``` ```
github "socketio/socket.io-client-swift" ~> 8.3.3 # Or latest version github "socketio/socket.io-client-swift" ~> 8.3.3 # Or latest version
@ -100,8 +97,7 @@ github "socketio/socket.io-client-swift" ~> 8.3.3 # Or latest version
Run `carthage update --platform ios,macosx`. Run `carthage update --platform ios,macosx`.
CocoaPods 1.0.0 or later ### CocoaPods 1.0.0 or later
------------------
Create `Podfile` and add `pod 'Socket.IO-Client-Swift'`: Create `Podfile` and add `pod 'Socket.IO-Client-Swift'`:
```ruby ```ruby
@ -131,8 +127,7 @@ Objective-C:
@import SocketIO; @import SocketIO;
``` ```
CocoaSeeds ### CocoaSeeds
-----------------
Add this line to your `Seedfile`: Add this line to your `Seedfile`:
@ -143,15 +138,14 @@ github "socketio/socket.io-client-swift", "v8.3.3", :files => "Source/*.swift" #
Run `seed install`. Run `seed install`.
##API ## API
Constructors
----------- ### Constructors
`init(var socketURL: NSURL, config: SocketIOClientConfiguration = [])` - Creates a new SocketIOClient. If your socket.io server is secure, you need to specify `https` in your socketURL. `init(var socketURL: NSURL, config: SocketIOClientConfiguration = [])` - Creates a new SocketIOClient. If your socket.io server is secure, you need to specify `https` in your socketURL.
`convenience init(socketURL: NSURL, options: NSDictionary?)` - Same as above, but meant for Objective-C. See Options on how convert between SocketIOClientOptions and dictionary keys. `convenience init(socketURL: NSURL, options: NSDictionary?)` - Same as above, but meant for Objective-C. See Options on how convert between SocketIOClientOptions and dictionary keys.
Options ### Options
-------
All options are a case of SocketIOClientOption. To get the Objective-C Option, convert the name to lowerCamelCase. All options are a case of SocketIOClientOption. To get the Objective-C Option, convert the name to lowerCamelCase.
```swift ```swift
@ -176,8 +170,7 @@ case security(SSLSecurity) // Allows you to set which certs are valid. Useful fo
case selfSigned(Bool) // Sets WebSocket.selfSignedSSL. Use this if you're using self-signed certs. case selfSigned(Bool) // Sets WebSocket.selfSignedSSL. Use this if you're using self-signed certs.
case voipEnabled(Bool) // Only use this option if you're using the client with VoIP services. Changes the way the WebSocket is created. Default is false case voipEnabled(Bool) // Only use this option if you're using the client with VoIP services. Changes the way the WebSocket is created. Default is false
``` ```
Methods ### Methods
-------
1. `on(_ event: String, callback: NormalCallback) -> NSUUID` - Adds a handler for an event. Items are passed by an array. `ack` can be used to send an ack when one is requested. See example. Returns a unique id for the handler. 1. `on(_ event: String, callback: NormalCallback) -> NSUUID` - Adds a handler for an event. Items are passed by an array. `ack` can be used to send an ack when one is requested. See example. Returns a unique id for the handler.
2. `once(_ event: String, callback: NormalCallback) -> NSUUID` - Adds a handler that will only be executed once. Returns a unique id for the handler. 2. `once(_ event: String, callback: NormalCallback) -> NSUUID` - Adds a handler that will only be executed once. Returns a unique id for the handler.
3. `onAny(callback:((event: String, items: AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event. 3. `onAny(callback:((event: String, items: AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event.
@ -195,18 +188,17 @@ Methods
15. `off(id id: NSUUID)` - Removes the event that corresponds to id. 15. `off(id id: NSUUID)` - Removes the event that corresponds to id.
16. `removeAllHandlers()` - Removes all handlers. 16. `removeAllHandlers()` - Removes all handlers.
Client Events ### Client Events
------
1. `connect` - Emitted when on a successful connection. 1. `connect` - Emitted when on a successful connection.
2. `disconnect` - Emitted when the connection is closed. 2. `disconnect` - Emitted when the connection is closed.
3. `error` - Emitted on an error. 3. `error` - Emitted on an error.
4. `reconnect` - Emitted when the connection is starting to reconnect. 4. `reconnect` - Emitted when the connection is starting to reconnect.
5. `reconnectAttempt` - Emitted when attempting to reconnect. 5. `reconnectAttempt` - Emitted when attempting to reconnect.
##Detailed Example ## Detailed Example
A more detailed example can be found [here](https://github.com/nuclearace/socket.io-client-swift-example) A more detailed example can be found [here](https://github.com/nuclearace/socket.io-client-swift-example)
An example using the Swift Package Manager can be found [here](https://github.com/nuclearace/socket.io-client-swift-spm-example) An example using the Swift Package Manager can be found [here](https://github.com/nuclearace/socket.io-client-swift-spm-example)
##License ## License
MIT MIT