要指定https在你的socketURL參數(shù)中.
convenience init(socketURL: NSURL, options: NSDictionary?)
同上, 但是為了ObjC準(zhǔn)備,使用字典.
Options
所有關(guān)于SocketIOClientOption的設(shè)置.如果是ObjC,轉(zhuǎn)換名字lowerCamelCase.
case ConnectParams([String: AnyObject]) // 通過字典內(nèi)容連接
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]) // 添加自定義請求頭初始化來請求, 默認(rèn)為nil
case ForcePolling(Bool) // 是否使用 xhr-polling. Default is `false`
case ForceNew(Bool) // 將為每個連接創(chuàng)建一個新的connect, 如果你在重新連接時有bug時使用.
case ForceWebsockets(Bool) // 是否使用 WebSockets. Default is `false`
case HandleQueue(dispatch_queue_t) // 調(diào)度handle的運(yùn)行隊(duì)列. Default is the main queue.
case Log(Bool) // 是否打印調(diào)試信息. Default is false.
case Logger(SocketLogger) // 可自定義SocketLogger調(diào)試日志.默認(rèn)是系統(tǒng)的.
case Nsp(String) // 如果使用命名空間連接. Must begin with /. Default is `/`
case Path(String) // 如果服務(wù)器使用一個自定義路徑. 例如: `"/swift/"`. Default is `""`
case Reconnects(Bool) // 是否重新連接服務(wù)器失敗. Default is `true`
case ReconnectAttempts(Int) // 重新連接多少次. Default is `-1` (無限次)
case ReconnectWait(Int) // 等待重連時間. Default is `10`
case SessionDelegate(NSURLSessionDelegate) // NSURLSessionDelegate 底層引擎設(shè)置. 如果你需要處理自簽名證書. Default is nil.
case Secure(Bool) // 如果連接要使用TLS. Default is false.
case SelfSigned(Bool) // WebSocket.selfSignedSSL設(shè)置 (Don't do this, iOS will yell at you)
case VoipEnabled(Bool) // 如果你的客戶端使用VoIP服務(wù),只有用這個選項(xiàng),Default is false
方法
on(event: String, callback: NormalCallback) -> NSUUID // 給一個事件添加一個句柄. Items are passed by an array. 可以發(fā)送ack請求. 例如,返回一個唯一ID.
once(event: String, callback: NormalCallback) -> NSUUID // 同上,但只執(zhí)行一次.
onAny(callback:((event: String, items: AnyObject?)) -> Void) //可以給所有事件添加一個句柄. event可以接收任何事件.
emit(event: String, _ items: AnyObject...) // 發(fā)送一個或多條消息.
emit(event: String, withItems items: [AnyObject]) // emit for Objective-C
emitWithAck(event: String, _ items: AnyObject...) -> (timeoutAfter: UInt64, callback: (NSArray?) -> Void) -> Void // 給服務(wù)器發(fā)送一個ack確認(rèn)請求. 返回一個函數(shù),你可以用它添加一個句柄. 注意: 直到你調(diào)用這個返回函數(shù),才會發(fā)送消息
emitWithAck(event: String, withItems items: [AnyObject]) -> (UInt64, (NSArray?) -> Void) -> Void // 同上,為Objective-C準(zhǔn)備的
connect() // 建立一個連接到服務(wù)器. 連接成功會觸發(fā) "connect"事件
connect(timeoutAfter timeoutAfter: Int, withTimeoutHandler handler: (() -> Void)?) // 連接到服務(wù)器. 如果連接超時,會調(diào)用handle
disconnect() // Closes the socket. 重開一個斷開連接的socket還沒完全測試.
reconnect() // Causes the client to reconnect to the server.
joinNamespace(namespace: String) - Causes the client to join namespace. 不應(yīng)該被調(diào)用,除非你手動改變命名空間.
leaveNamespace() // Causes the client to leave the nsp and go back to '/'
off(event: String) - Removes all event handlers for event.
off(id id: NSUUID) - Removes the event that corresponds to id.
removeAllHandlers() - Removes all handlers.
客戶端的事件
connect – 當(dāng)成功連接時Emitted
disconnect – 當(dāng)連接斷開Emitted
error – 發(fā)送錯誤時Emitted
reconnect – 當(dāng)開始重連時Emitted
reconnectAttempt – 當(dāng)嘗試重連時Emitted