Hi, I am a beginner and Im trying to output labels TLM HAS PAPER or TLM HAS NO PAPER to my iPhone 6.
My code is below.
Input Html into a string, then I find the character string relevant...ie "Sensor is:</2>OFF" . Then print label to my phone. It sometimes works if I move the code around, but only cycle a few times.
I installed a timer to slow the code down so the label can maybe will print, but this has failed.
Any guidance appreciated.
//
// ViewController.swift
// TLMv25_11_18
//
//
//
//
import UIKit
import WebKit
class ViewController: UIViewController { //A
@IBOutlet weak var webView: WKWebView!
@IBOutlet weak var alarm: UILabel!
override func viewDidLoad() { //B
super.viewDidLoad()
let myURL = URL(string:"http://192.168.4.1")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
print("step 1")
var i = 300000
if let url = URL(string: "http://192.168.4.1") { //J
do { //I
let contents = try String(contentsOf: url)
print("step 2")
print(contents)
if contents.contains("Sensor is:</2>ON") { //F
print("** sensor is on")
while i >= 0 { //k
alarm.text = "TLM HAS PAPER"
//delay here
print(i)
i -= 1
} //k
print("this is working here in my code")
print("step 3")
} //F
if contents.contains("Sensor is:</2>OFF") { //G
print("step 4")
print("sensor is off")
alarm.text = "NO PAPER"
print("code working to here")
} //G
} //J
catch { //E
print("check wifi")
print("step 5")
} //E
print("step 6")
} //I
print("step 7")
viewDidLoad()
} //B
} //A