You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Copy the SwiftIO folder into your Xcode project!
@@ -36,13 +73,23 @@ Import in your swift file:
36
73
importSocket_IO_Client_Swift
37
74
```
38
75
39
-
API
40
-
===
76
+
##API
41
77
Constructors
42
78
-----------
43
-
`init(socketURL: String, opts:NSDictionary? = nil)` - Constructs a new client for the given URL. opts can be omitted (will use default values. See example)
79
+
`init(socketURL: String, opts:NSDictionary? = nil)` - Constructs a new client for the given URL. opts can be omitted (will use default values)
44
80
45
81
`convenience init(socketURL: String, options:NSDictionary?)` - Same as above, but meant for Objective-C. See Objective-C Example.
82
+
83
+
Options
84
+
-------
85
+
-`reconnects: Bool` Default is `true`
86
+
-`reconnectAttempts: Int` Default is `-1` (infinite tries)
87
+
-`reconnectWait: Int` Default is `10`
88
+
-`forcePolling: Bool` Default is `false`. `true` forces the client to use xhr-polling.
89
+
-`forceWebsockets: Bool` Default is `false`. `true` forces the client to use WebSockets.
90
+
-`nsp: String` Default is `"/"`
91
+
-`cookies: [NSHTTPCookie]?` An array of NSHTTPCookies. Passed during the handshake. Default is nil.
92
+
46
93
Methods
47
94
-------
48
95
1.`socket.on(name:String, callback:((data:NSArray?, ack:AckEmitter?) -> Void))` - 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.
@@ -63,87 +110,8 @@ Events
63
110
4.`reconnect` - Emitted when the connection is starting to reconnect.
64
111
5.`reconnectAttempt` - Emitted when attempting to reconnect.
65
112
66
-
Example
67
-
=======
68
-
```swift
69
-
// opts can be omitted, will use default values
70
-
let socket =SocketIOClient(socketURL: "https://localhost:8080", opts: [
71
-
"reconnects":true, // Default is true
72
-
"reconnectAttempts":5, // Default is -1 (infinite tries)
73
-
"reconnectWait":5, // Default is 10
74
-
"nsp":"swift", // connects to the specified namespace. Default is /
75
-
"forcePolling":true, // if true the client will only use XHR polling, Default is false (polling/WebSockets)
76
-
"forceWebsockets":false, // if true the client will only use WebSockets. Trumps forcePolling. Default is false. (polling/WebSockets)
77
-
"cookies":nil// An array of NSHTTPCookies. Passed during handshake. Default is nil
78
-
])
79
-
80
-
// Called on every event
81
-
socket.onAny {println("got event: \($0.event) with items \($0.items)")}
82
-
83
-
// Socket Events
84
-
socket.on("connect") {data, ack in
85
-
println("socket connected")
86
-
87
-
// Sending messages
88
-
socket.emit("testEcho")
89
-
90
-
socket.emit("testObject", [
91
-
"data":true
92
-
])
93
-
94
-
// Sending multiple items per message
95
-
socket.emit("multTest", [1], 1.4, 1, "true",
96
-
true, ["test":"foo"], "bar")
97
-
}
98
-
99
-
// Requesting acks, and responding to acks
100
-
socket.on("ackEvent") {data, ack in
101
-
iflet str = data?[0] as?String {
102
-
println("Got ackEvent")
103
-
}
104
-
105
-
// data is an array
106
-
iflet int = data?[1] as?Int {
107
-
println("Got int")
108
-
}
109
-
110
-
// You can specify a custom timeout interval. 0 means no timeout.
111
-
socket.emitWithAck("ackTest", "test").onAck(0) {data in
0 commit comments