youngmonkeys / ezyfox-server-swift-client

ezyfox-server-swift-client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ezyfox-server-swift-client

swift client for ezyfox server

Synopsis

swift client for ezyfox server

Documentation

https://youngmonkeys.org/ezyfox-swift-client-sdk/

Using by

Code Example

1. Create a TCP Client

let config = NSMutableDictionary()
config["clientName"] = ZONE_APP_NAME
let clients = EzyClients.getInstance()!
client = clients.newClient(config: config)

2. Setup client

 let setup = client.setup!
    .addEventHandler(eventType: EzyEventType.CONNECTION_SUCCESS, handler: EzyConnectionSuccessHandler())
    .addEventHandler(eventType: EzyEventType.CONNECTION_FAILURE, handler: EzyConnectionFailureHandler())
    .addEventHandler(eventType: EzyEventType.DISCONNECTION, handler: ExDisconnectionHandler())
    .addDataHandler(cmd: EzyCommand.LOGIN, handler: ExLoginSuccessHandler())
    .addDataHandler(cmd: EzyCommand.APP_ACCESS, handler: ExAppAccessHandler())
    .addDataHandler(cmd: EzyCommand.HANDSHAKE, handler: ExHandshakeHandler())

3. Setup app

 = setup.setupApp(appName: ZONE_APP_NAME)
    .addDataHandler(cmd: Commands.GET_CONTACTS, handler: GetContactsResponseHandler())
    .addDataHandler(cmd: Commands.SEARCH_EXISTED_CONTACTS, handler: SearchExistedContactsResponseHandler())
    .addDataHandler(cmd: Commands.SUGGEST_CONTACTS, handler: SuggestContactsResponseHandler())

4. Connect to server

client.connect(host: host, port: 3005)

5. Run event loop

clients.processEvents()

6. Custom event handler

class ExDisconnectionHandler: EzyDisconnectionHandler {
    override func postHandle(event: NSDictionary) {
        // do something here
    }
}

8. Logger usage

You should set main thread's name first:

Thread.current.name = "main";

Logger usage:

EzyLogger.info(msg: "access app: \(app.name) successfully")

About

ezyfox-server-swift-client


Languages

Language:Swift 47.3%Language:Objective-C++ 40.8%Language:Objective-C 11.1%Language:C 0.8%