diff --git a/README.md b/README.md index 1db6a38..54f9000 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Socket.IO-client for iOS/OS X. ##Example ```swift -let socket = SocketIOClient(socketURL: NSURL(string: "http://localhost:8080")!, options: [.Log(true), .ForcePolling(true)]) +let socket = SocketIOClient(socketURL: NSURL(string: "http://localhost:8080")!, options: [.log(true), .forcePolling(true)]) socket.on("connect") {data, ack in print("socket connected") @@ -55,13 +55,15 @@ SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url options:@ - Can be used from Objective-C ##Installation -Requires Swift 2.2/Xcode 7.3 +Requires Swift 3/Xcode 8.x -If you need Swift 2.1/Xcode 7.2 use v5.5.0 (Pre-Swift 2.2 support is no longer maintained) +If you need swift 2.2 use 6.x (Pre-Swift 3 support is no longer maintained) -If you need Swift 1.2/Xcode 6.3/4 use v2.4.5 (Pre-Swift 2 support is no longer maintained) +If you need Swift 2.1 use v5.5.0 (Pre-Swift 2.2 support is no longer maintained) -If you need Swift 1.1/Xcode 6.2 use v1.5.2. (Pre-Swift 1.2 support is no longer maintained) +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) Manually (iOS 7+) ----------------- @@ -148,43 +150,43 @@ 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 +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. +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...) -> (timeoutAfter: UInt64, callback: (NSArray?) -> Void) -> Void` - Sends a message that requests an acknowledgement from the server. Returns a function which you can use to add a handler. See example. Note: The message is not sent until you call the returned function. -7. `emitWithAck(event: String, withItems items: [AnyObject]) -> (UInt64, (NSArray?) -> Void) -> Void` - `emitWithAck` for Objective-C. Note: The message is not sent until you call the returned function. +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...) -> (timeoutAfter: UInt64, callback: (NSArray?) -> Void) -> Void` - Sends a message that requests an acknowledgement from the server. Returns a function which you can use to add a handler. See example. Note: The message is not sent until you call the returned function. +7. `emitWithAck(_ event: String, withItems items: [AnyObject]) -> (UInt64, (NSArray?) -> Void) -> Void` - `emitWithAck` for Objective-C. Note: The message is not sent until you call the returned function. 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. +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. +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.