Paso 18: Código de ESP8266 - continuó
El código final debe así:
importar la clase de UIKit ViewController: UIViewController {} import UIKit class ViewController: UIViewController { weak var web: UIWebView! weak var label: UILabel! weak var slider: UISlider! var onURLPath = "http://192.168.4.1/?pin=ONA" var offURLPath = "http://192.168.4.1/?pin=OFFA" var on1URLPath = "http://192.168.4.1/?pin=ONB" var off1URLPath = "http://192.168.4.1/?pin=OFFB" var on2URLPath = "http://192.168.4.1/?pin=ONC" var off2URLPath = "http://192.168.4.1/?pin=OFFC" var on3URLPath = "http://192.168.4.1/?pin=OND" var off3URLPath = "http://192.168.4.1/?pin=OFFD" override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } //UP func buttonTouched(sender: UIButton) { let requestURL = NSURL(string: onURLPath+"\(label.text!)") let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } func buttonReleased(sender: UIButton) { let requestURL = NSURL(string: offURLPath) let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } //Down func buttonTouched1(sender: UIButton) { let requestURL = NSURL(string: on1URLPath+"\(label.text!)") let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } func buttonReleased1(sender: UIButton) { let requestURL = NSURL(string: off1URLPath) let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } //Left func buttonTouchedLeft(sender: UIButton) { let requestURL = NSURL(string: on2URLPath+"\(label.text!)") let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } func buttonReleasedLeft(sender: UIButton) { let requestURL = NSURL(string: off2URLPath) let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } //Right func buttonTouched3(sender: UIButton) { let requestURL = NSURL(string: on3URLPath+"\(label.text!)") let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } func buttonReleased3(sender: UIButton) { let requestURL = NSURL(string: off3URLPath) let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } //Slider func sliderValueChanged(sender: UISlider) { var currentValue = Int(sender.value) label.text = "\(currentValue)" } } var onURLPath = "http://192.168.4.1/?pin=ONA" var offURLPath = "http://192.168.4.1/?pin=OFFA" var on1URLPath = "http://192.168.4.1/?pin=ONB" var off1URLPath = "http://192.168.4.1/?pin=OFFB" var on2URLPath = "http://192.168.4.1/?pin=ONC" var off2URLPath = "http://192.168.4.1/?pin=OFFC" var on3URLPath = "http://192.168.4.1/?pin=OND" var off3URLPath = "http://192.168.4.1/?pin=OFFD" anulación func viewDidLoad() {super.viewDidLoad() / / hacer cualquier configuración adicional después de cargar el vista, típicamente de un plumín.} reemplazar func didReceiveMemoryWarning() {super.didReceiveMemoryWarning() / / disponer de cualquier recurso que puede ser recreado.} //UPFUNC buttonReleased(sender: UIButton) {que requestURL = NSURL(string: offURLPath) deje solicitud = NSURLRequest (URL: requestURL!) web.loadRequest(request) print(requestURL!)} func //Down buttonTouched1(sender: UIButton) {que requestURL = NSURL(string: on1URLPath+"\(label.text!)") dejar petición = NSURLRequest (URL: requestURL!) web.loadRequest(request) print(requestURL!)} FUNC buttonReleased1(sender: UIButton) {que requestURL = NSURL(string: off1URLPath) deje solicitud = NSURLRequest (URL: requestURL!) web.loadRequest(request) print(requestURL!)} func //Left buttonTouchedLeft(sender: UIButton) {que requestURL = NSURL(string: on2URLPath+"\(label.text!)") dejar petición = NSURLRequest (URL: requestURL!) web.loadRequest(request) print(requestURL!)} FUNC buttonReleasedLeft(sender: UIButton) {que requestURL = NSURL(string: off2URLPath) deje solicitud = NSURLRequest (URL: requestURL!) web.loadRequest(request) print(requestURL!)} func //Right buttonTouched3(sender: UIButton) {que requestURL = NSURL(string: on3URLPath+"\(label.text!)") dejar petición = NSURLRequest (URL: requestURL!) web.loadRequest(request) print(requestURL!)} FUNC buttonReleased3(sender: UIButton) {que requestURL = NSURL(string: off3URLPath) deje solicitud = NSURLRequest (URL: requestURL!) web.loadRequest(request) print(requestURL!)} //Slider