I have a PHP script that executes a local command and prints and flushes the stdout. For example, it would print something like
1
and then after a second
1 2
and then after a second
1 2 3
So on and so forth. I want to be able to get that data as it comes in iOS. I found this function but it does not return anything until the page fully loads:
@IBAction func doButton (sender:AnyObject!) {
let url = NSURL(string: "http://mywebsite.local/script.php")!
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url, completionHandler: {
(data, response, error) in
print(NSString(data: data!, encoding: NSUTF8StringEncoding))
})
task.resume()
}
Any ideas on how I can flush the data as it comes?