update docs

This commit is contained in:
Erik 2017-05-07 11:56:03 -04:00
parent 74fa4142d6
commit a7c90cdac9
No known key found for this signature in database
GPG Key ID: 4930B7C5FBC1A69D
2 changed files with 18 additions and 121 deletions

View File

@ -82,7 +82,7 @@ import PackageDescription
let package = Package(
name: "YourSocketIOProject",
dependencies: [
.Package(url: "https://github.com/socketio/socket.io-client-swift", majorVersion: 8)
.Package(url: "https://github.com/socketio/socket.io-client-swift", majorVersion: 9)
]
)
```
@ -92,7 +92,7 @@ Then import `import SocketIO`.
### Carthage
Add this line to your `Cartfile`:
```
github "socketio/socket.io-client-swift" ~> 8.3.3 # Or latest version
github "socketio/socket.io-client-swift" ~> 9.0.0 # Or latest version
```
Run `carthage update --platform ios,macosx`.
@ -104,7 +104,7 @@ Create `Podfile` and add `pod 'Socket.IO-Client-Swift'`:
use_frameworks!
target 'YourApp' do
pod 'Socket.IO-Client-Swift', '~> 8.3.3' # Or latest version
pod 'Socket.IO-Client-Swift', '~> 9.0.0' # Or latest version
end
```
@ -132,68 +132,17 @@ Objective-C:
Add this line to your `Seedfile`:
```
github "socketio/socket.io-client-swift", "v8.3.3", :files => "Source/*.swift" # Or latest version
github "socketio/socket.io-client-swift", "v9.0.0", :files => "Source/*.swift" # Or latest version
```
Run `seed install`.
# API
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.
# [Docs](https://nuclearace.github.io/Socket.IO-Client-Swift/index.html)
`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
All options are a case of SocketIOClientOption. To get the Objective-C Option, convert the name to lowerCamelCase.
```swift
case connectParams([String: AnyObject]) // Dictionary whose contents will be passed with the connection.
case cookies([NSHTTPCookie]) // An array of NSHTTPCookies. Passed during the handshake. Default is nil.
case doubleEncodeUTF8(Bool) // Whether or not to double encode utf8. If using the node based server this should be true. Default is true.
case extraHeaders([String: String]) // Adds custom headers to the initial request. Default is nil.
case forcePolling(Bool) // `true` forces the client to use xhr-polling. Default is `false`
case forceNew(Bool) // Will a create a new engine for each connect. Useful if you find a bug in the engine related to reconnects
case forceWebsockets(Bool) // `true` forces the client to use WebSockets. Default is `false`
case handleQueue(dispatch_queue_t) // The dispatch queue that handlers are run on. Default is the main queue.
case log(Bool) // If `true` socket will log debug messages. Default is false.
case logger(SocketLogger) // Custom logger that conforms to SocketLogger. Will use the default logging otherwise.
case nsp(String) // The namespace to connect to. Must begin with /. Default is `/`
case path(String) // If the server uses a custom path. ex: `"/swift/"`. Default is `""`
case reconnects(Bool) // Whether to reconnect on server lose. Default is `true`
case reconnectAttempts(Int) // How many times to reconnect. Default is `-1` (infinite tries)
case reconnectWait(Int) // Amount of time to wait between reconnects. Default is `10`
case sessionDelegate(NSURLSessionDelegate) // Sets an NSURLSessionDelegate for the underlying engine. Useful if you need to handle self-signed certs. Default is nil.
case secure(Bool) // If the connection should use TLS. Default is false.
case security(SSLSecurity) // Allows you to set which certs are valid. Useful for SSL pinning.
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
```
### 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.
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.
4. `emit(_ event: String, _ items: AnyObject...)` - Sends a message. Can send multiple items.
5. `emit(_ event: String, withItems items: [AnyObject])` - `emit` for Objective-C
6. `emitWithAck(_ event: String, _ items: AnyObject...) -> OnAckCallback` - Sends a message that requests an acknowledgement from the server. Returns an object which you can use to add a handler. See example. Note: The message is not sent until you call timingOut(after:) on the returned object.
7. `emitWithAck(_ event: String, withItems items: [AnyObject]) -> OnAckCallback` - `emitWithAck` for Objective-C. Note: The message is not sent until you call timingOutAfter on the returned object.
8. `connect()` - Establishes a connection to the server. A "connect" event is fired upon successful connection.
9. `connect(timeoutAfter timeoutAfter: Int, withTimeoutHandler handler: (() -> Void)?)` - Connect to the server. If it isn't connected after timeoutAfter seconds, the handler is called.
10. `disconnect()` - Closes the socket. Reopening a disconnected socket is not fully tested.
11. `reconnect()` - Causes the client to reconnect to the server.
12. `joinNamespace(_ namespace: String)` - Causes the client to join namespace. Shouldn't need to be called unless you change namespaces manually.
13. `leaveNamespace()` - Causes the client to leave the nsp and go back to /
14. `off(_ event: String)` - Removes all event handlers for event.
15. `off(id id: NSUUID)` - Removes the event that corresponds to id.
16. `removeAllHandlers()` - Removes all handlers.
### Client Events
1. `connect` - Emitted when on a successful connection.
2. `disconnect` - Emitted when the connection is closed.
3. `error` - Emitted on an error.
4. `reconnect` - Emitted when the connection is starting to reconnect.
5. `reconnectAttempt` - Emitted when attempting to reconnect.
- [Client](https://nuclearace.github.io/Socket.IO-Client-Swift/Classes/SocketIOClient.html)
- [Engine](https://nuclearace.github.io/Socket.IO-Client-Swift/Classes/SocketEngine.html)
- [Options](https://nuclearace.github.io/Socket.IO-Client-Swift/Enums/SocketIOClientOption.html)
## Detailed Example
A more detailed example can be found [here](https://github.com/nuclearace/socket.io-client-swift-example)

View File

@ -253,7 +253,7 @@ SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{
<span class="k">let</span> <span class="nv">package</span> <span class="o">=</span> <span class="kt">Package</span><span class="p">(</span>
<span class="nv">name</span><span class="p">:</span> <span class="s">"YourSocketIOProject"</span><span class="p">,</span>
<span class="nv">dependencies</span><span class="p">:</span> <span class="p">[</span>
<span class="o">.</span><span class="kt">Package</span><span class="p">(</span><span class="nv">url</span><span class="p">:</span> <span class="s">"https://github.com/socketio/socket.io-client-swift"</span><span class="p">,</span> <span class="nv">majorVersion</span><span class="p">:</span> <span class="mi">8</span><span class="p">)</span>
<span class="o">.</span><span class="kt">Package</span><span class="p">(</span><span class="nv">url</span><span class="p">:</span> <span class="s">"https://github.com/socketio/socket.io-client-swift"</span><span class="p">,</span> <span class="nv">majorVersion</span><span class="p">:</span> <span class="mi">9</span><span class="p">)</span>
<span class="p">]</span>
<span class="p">)</span>
</code></pre>
@ -262,7 +262,7 @@ SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{
<h3 id='carthage' class='heading'>Carthage</h3>
<p>Add this line to your <code>Cartfile</code>:</p>
<pre class="highlight plaintext"><code>github "socketio/socket.io-client-swift" ~&gt; 8.3.3 # Or latest version
<pre class="highlight plaintext"><code>github "socketio/socket.io-client-swift" ~&gt; 9.0.0 # Or latest version
</code></pre>
<p>Run <code>carthage update --platform ios,macosx</code>.</p>
@ -272,7 +272,7 @@ SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{
<pre class="highlight ruby"><code><span class="n">use_frameworks!</span>
<span class="n">target</span> <span class="s1">'YourApp'</span> <span class="k">do</span>
<span class="n">pod</span> <span class="s1">'Socket.IO-Client-Swift'</span><span class="p">,</span> <span class="s1">'~&gt; 8.3.3'</span> <span class="c1"># Or latest version</span>
<span class="n">pod</span> <span class="s1">'Socket.IO-Client-Swift'</span><span class="p">,</span> <span class="s1">'~&gt; 9.0.0'</span> <span class="c1"># Or latest version</span>
<span class="k">end</span>
</code></pre>
@ -292,69 +292,17 @@ SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{
<h3 id='cocoaseeds' class='heading'>CocoaSeeds</h3>
<p>Add this line to your <code>Seedfile</code>:</p>
<pre class="highlight plaintext"><code>github "socketio/socket.io-client-swift", "v8.3.3", :files =&gt; "Source/*.swift" # Or latest version
<pre class="highlight plaintext"><code>github "socketio/socket.io-client-swift", "v9.0.0", :files =&gt; "Source/*.swift" # Or latest version
</code></pre>
<p>Run <code>seed install</code>.</p>
<h1 id='api' class='heading'>API</h1>
<h2 id='constructors' class='heading'>Constructors</h2>
<h1 id='a-href-https-nuclearace-github-io-socket-io-client-swift-index-html-docs-a' class='heading'><a href="https://nuclearace.github.io/Socket.IO-Client-Swift/index.html">Docs</a></h1>
<p><code>init(var socketURL: NSURL, config: SocketIOClientConfiguration = [])</code> - Creates a new SocketIOClient. If your socket.io server is secure, you need to specify <code>https</code> in your socketURL.</p>
<p><code>convenience init(socketURL: NSURL, options: NSDictionary?)</code> - Same as above, but meant for Objective-C. See Options on how convert between SocketIOClientOptions and dictionary keys.</p>
<h3 id='options' class='heading'>Options</h3>
<p>All options are a case of SocketIOClientOption. To get the Objective-C Option, convert the name to lowerCamelCase.</p>
<pre class="highlight swift"><code><span class="k">case</span> <span class="nf">connectParams</span><span class="p">([</span><span class="kt">String</span><span class="p">:</span> <span class="kt">AnyObject</span><span class="p">])</span> <span class="c1">// Dictionary whose contents will be passed with the connection.</span>
<span class="k">case</span> <span class="nf">cookies</span><span class="p">([</span><span class="kt">NSHTTPCookie</span><span class="p">])</span> <span class="c1">// An array of NSHTTPCookies. Passed during the handshake. Default is nil.</span>
<span class="k">case</span> <span class="nf">doubleEncodeUTF8</span><span class="p">(</span><span class="kt">Bool</span><span class="p">)</span> <span class="c1">// Whether or not to double encode utf8. If using the node based server this should be true. Default is true.</span>
<span class="k">case</span> <span class="nf">extraHeaders</span><span class="p">([</span><span class="kt">String</span><span class="p">:</span> <span class="kt">String</span><span class="p">])</span> <span class="c1">// Adds custom headers to the initial request. Default is nil.</span>
<span class="k">case</span> <span class="nf">forcePolling</span><span class="p">(</span><span class="kt">Bool</span><span class="p">)</span> <span class="c1">// `true` forces the client to use xhr-polling. Default is `false`</span>
<span class="k">case</span> <span class="nf">forceNew</span><span class="p">(</span><span class="kt">Bool</span><span class="p">)</span> <span class="c1">// Will a create a new engine for each connect. Useful if you find a bug in the engine related to reconnects</span>
<span class="k">case</span> <span class="nf">forceWebsockets</span><span class="p">(</span><span class="kt">Bool</span><span class="p">)</span> <span class="c1">// `true` forces the client to use WebSockets. Default is `false`</span>
<span class="k">case</span> <span class="nf">handleQueue</span><span class="p">(</span><span class="n">dispatch_queue_t</span><span class="p">)</span> <span class="c1">// The dispatch queue that handlers are run on. Default is the main queue.</span>
<span class="k">case</span> <span class="nf">log</span><span class="p">(</span><span class="kt">Bool</span><span class="p">)</span> <span class="c1">// If `true` socket will log debug messages. Default is false.</span>
<span class="k">case</span> <span class="nf">logger</span><span class="p">(</span><span class="kt">SocketLogger</span><span class="p">)</span> <span class="c1">// Custom logger that conforms to SocketLogger. Will use the default logging otherwise.</span>
<span class="k">case</span> <span class="nf">nsp</span><span class="p">(</span><span class="kt">String</span><span class="p">)</span> <span class="c1">// The namespace to connect to. Must begin with /. Default is `/`</span>
<span class="k">case</span> <span class="nf">path</span><span class="p">(</span><span class="kt">String</span><span class="p">)</span> <span class="c1">// If the server uses a custom path. ex: `"/swift/"`. Default is `""`</span>
<span class="k">case</span> <span class="nf">reconnects</span><span class="p">(</span><span class="kt">Bool</span><span class="p">)</span> <span class="c1">// Whether to reconnect on server lose. Default is `true`</span>
<span class="k">case</span> <span class="nf">reconnectAttempts</span><span class="p">(</span><span class="kt">Int</span><span class="p">)</span> <span class="c1">// How many times to reconnect. Default is `-1` (infinite tries)</span>
<span class="k">case</span> <span class="nf">reconnectWait</span><span class="p">(</span><span class="kt">Int</span><span class="p">)</span> <span class="c1">// Amount of time to wait between reconnects. Default is `10`</span>
<span class="k">case</span> <span class="nf">sessionDelegate</span><span class="p">(</span><span class="kt">NSURLSessionDelegate</span><span class="p">)</span> <span class="c1">// Sets an NSURLSessionDelegate for the underlying engine. Useful if you need to handle self-signed certs. Default is nil.</span>
<span class="k">case</span> <span class="nf">secure</span><span class="p">(</span><span class="kt">Bool</span><span class="p">)</span> <span class="c1">// If the connection should use TLS. Default is false.</span>
<span class="k">case</span> <span class="nf">security</span><span class="p">(</span><span class="kt">SSLSecurity</span><span class="p">)</span> <span class="c1">// Allows you to set which certs are valid. Useful for SSL pinning.</span>
<span class="k">case</span> <span class="nf">selfSigned</span><span class="p">(</span><span class="kt">Bool</span><span class="p">)</span> <span class="c1">// Sets WebSocket.selfSignedSSL. Use this if you're using self-signed certs.</span>
<span class="k">case</span> <span class="nf">voipEnabled</span><span class="p">(</span><span class="kt">Bool</span><span class="p">)</span> <span class="c1">// Only use this option if you're using the client with VoIP services. Changes the way the WebSocket is created. Default is false</span>
</code></pre>
<h3 id='methods' class='heading'>Methods</h3>
<ol>
<li><code>on(_ event: String, callback: NormalCallback) -&gt; NSUUID</code> - Adds a handler for an event. Items are passed by an array. <code>ack</code> can be used to send an ack when one is requested. See example. Returns a unique id for the handler.</li>
<li><code>once(_ event: String, callback: NormalCallback) -&gt; NSUUID</code> - Adds a handler that will only be executed once. Returns a unique id for the handler.</li>
<li><code>onAny(callback:((event: String, items: AnyObject?)) -&gt; Void)</code> - Adds a handler for all events. It will be called on any received event.</li>
<li><code>emit(_ event: String, _ items: AnyObject...)</code> - Sends a message. Can send multiple items.</li>
<li><code>emit(_ event: String, withItems items: [AnyObject])</code> - <code>emit</code> for Objective-C</li>
<li><code>emitWithAck(_ event: String, _ items: AnyObject...) -&gt; OnAckCallback</code> - Sends a message that requests an acknowledgement from the server. Returns an object which you can use to add a handler. See example. Note: The message is not sent until you call timingOut(after:) on the returned object.</li>
<li><code>emitWithAck(_ event: String, withItems items: [AnyObject]) -&gt; OnAckCallback</code> - <code>emitWithAck</code> for Objective-C. Note: The message is not sent until you call timingOutAfter on the returned object.</li>
<li><code>connect()</code> - Establishes a connection to the server. A <q>connect</q> event is fired upon successful connection.</li>
<li><code>connect(timeoutAfter timeoutAfter: Int, withTimeoutHandler handler: (() -&gt; Void)?)</code> - Connect to the server. If it isn&rsquo;t connected after timeoutAfter seconds, the handler is called.</li>
<li><code>disconnect()</code> - Closes the socket. Reopening a disconnected socket is not fully tested.</li>
<li><code>reconnect()</code> - Causes the client to reconnect to the server.</li>
<li><code>joinNamespace(_ namespace: String)</code> - Causes the client to join namespace. Shouldn&rsquo;t need to be called unless you change namespaces manually.</li>
<li><code>leaveNamespace()</code> - Causes the client to leave the nsp and go back to /</li>
<li><code>off(_ event: String)</code> - Removes all event handlers for event.</li>
<li><code>off(id id: NSUUID)</code> - Removes the event that corresponds to id.</li>
<li><code>removeAllHandlers()</code> - Removes all handlers.</li>
</ol>
<h3 id='client-events' class='heading'>Client Events</h3>
<ol>
<li><code>connect</code> - Emitted when on a successful connection.</li>
<li><code>disconnect</code> - Emitted when the connection is closed.</li>
<li><code>error</code> - Emitted on an error.</li>
<li><code>reconnect</code> - Emitted when the connection is starting to reconnect.</li>
<li><code>reconnectAttempt</code> - Emitted when attempting to reconnect.</li>
</ol>
<ul>
<li><a href="https://nuclearace.github.io/Socket.IO-Client-Swift/Classes/SocketIOClient.html">Client</a></li>
<li><a href="https://nuclearace.github.io/Socket.IO-Client-Swift/Classes/SocketEngine.html">Engine</a></li>
<li><a href="https://nuclearace.github.io/Socket.IO-Client-Swift/Enums/SocketIOClientOption.html">Options</a></li>
</ul>
<h2 id='detailed-example' class='heading'>Detailed Example</h2>
<p>A more detailed example can be found <a href="https://github.com/nuclearace/socket.io-client-swift-example">here</a></p>