swift client for ezyfox server
swift client for ezyfox server
https://youngmonkeys.org/ezyfox-swift-client-sdk/
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")