在iOS上订阅std :: cout流(stdout)

时间:2018-08-26 10:53:07

标签: ios swift stdout cout

在我的应用中,我记录了所有内容并通过自定义记录器将其发送到云中。

我还使用了一些使用cout的C ++库。

我想利用cout流并将其发送到云中而无需更改C ++库。

我尝试使用FileHandle.standardOutput并将文本发送到UITextView(作为测试),但没有调用readabilityHandler

let fileHandler = FileHandle.standardOutput    
fileHandler.readabilityHandler = { fileHandler in
    let newText = String(data: fileHandler.availableData, encoding: .utf8) ?? "NO-Text"
    DispatchQueue.main.async {
        self.logTextView.text.append(newText)
        self.fileHandler.waitForDataInBackgroundAndNotify()
    }
}
fileHandler.waitForDataInBackgroundAndNotify()

有人尝试做类似的事情吗?知道我在做什么错吗?

0 个答案:

没有答案