samedi 9 mai 2015

how to update UILabel using sockets

I am trying to update a UILabel using swift and sockets. I have a Mean stack app working with sockets now. It updates a simple counter when a user presses a button. How could I use sockets and update a UILabel when a user presses a button on the client side of my Mean stack app? Below is the swift code I'm using to update the counter. Any help or suggestions would be greatly appreciated.

import Foundation
import UIKit

class SocketsController: UIViewController, UIAlertViewDelegate {

@IBOutlet weak var socketLabel: UILabel!

@IBAction func buttonOnePressed(sender: UIButton) {
    socket.emit("javascript")
}

@IBAction func buttonTwoPressed(sender: UIButton) {
    socket.emit("swift")

}


let socket = SocketIOClient(socketURL: "192.168.15.92:8000")

override func viewDidLoad() {
    super.viewDidLoad()
    socket.connect()

    socket.on("connect") { data, ack in
        println("iOS::WE ARE USING SOCKETS!")

    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

Aucun commentaire:

Enregistrer un commentaire