繁体   English   中英

来自部署在设备上的应用程序的 iOS os.log

[英]iOS os.log from an app deployed on device

我正在使用新的os.log东西登录我的应用程序,如下所示:

import os.log

class ViewController: UIViewController {
    // a bunch of methods
}

extension OSLog {
    static let ui = OSLog(subsystem: "io.my.app", category: "ui")
}

extension ViewController {        
    func upload(locations: [LocationProtocol]) {
        os_log("Sending locations to server", log: .ui, type: .debug)
        self.server_api.send(locations)
    }
}

当我从 Xcode 调试应用程序时,日志按预期显示在Console.app中。 但是是否有可能以某种方式从部署在设备上的应用程序实例中检索记录的字符串? 我正在“现场”测试我的应用程序,远离笔记本电脑,并希望将收集的日志转储到文本文件中。

我是否需要以某种方式配置记录器以持久存储日志,或者只能从已部署的应用程序获取崩溃报告?

注意:我使用的是Swift 4 / Xcode 9+

我相信你可以用这个答案解决这个问题: https : //stackoverflow.com/a/13303081/2136375

总结一下:

第1步

将以下代码添加到didFinishLaunchingWithOptions以使应用程序能够登录到文件:

var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let documentsDirectory = paths[0]
let deviceName = UIDevice.current.name
let fileName = "\(deviceName) - \(Date()).log"
let logFilePath = (documentsDirectory as NSString).appendingPathComponent(fileName) freopen(logFilePath.cString(using: String.Encoding.ascii)!, "a+", stderr)

第2步

info.plist添加:

替代 1

作为属性列表项:

“应用程序支持 iTunes 文件共享”并设置为 YES。

替代选项 2

作为源代码:

<key>UIFileSharingEnabled</key>
<true/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM