如何解决如何快速设置 PLCrashReporter.setCrashCallbacks?
我正在尝试使用 setCrashCallbacks
快速调用 setup PLCrashReporter,但不知何故显然没有调用回调。我可以看到我所有的 NSLog 调用都出现在 Console.app 中。我还可以在下次启动时看到文本格式的报告。但是,回调中的 NSLog 调用从未显示在 Console.app 中。
我怎样才能在 Swift 中做到这一点?甚至可以在 Swift 中做到这一点吗?还是我需要去 Objetive-C ?
// Added via SPM
import CrashReporter
// global scope function
func handleSignalForCrashReport(_ siginfo: UnsafeMutablePointer<siginfo_t>?,_ context: UnsafeMutablePointer<ucontext_t>?,_ something: UnsafeMutableRawPointer?) {
// This never shows ?
NSLog("crash rep handleSignalForCrashReport")
// Do my thing here ...
}
// global scope variable
var callbacks = PLCrashReporterCallbacks(version: 0,context: nil,handleSignal: handleSignalForCrashReport)
class AppDelegate: UIResponder,UIApplicationDelegate {
func setupCrashReporter() {
let config = PLCrashReporterConfig(signalHandlerType: .mach,symbolicationStrategy: .all)
NSLog("crash rep 1")
guard let crashReporter = PLCrashReporter(configuration: config) else {
NSLog("crash rep 1.1")
return
}
NSLog("crash rep 2")
crashReporter.setCrash(&callbacks)
do {
try crashReporter.enableAndReturnError()
NSLog("crash rep 3")
} catch {
NSLog("crash rep 4 Warning: Could not enable crash reporter: \(error.localizedDescription)")
}
if crashReporter.hasPendingCrashReport() {
do {
let data = try crashReporter.loadPendingCrashReportDataAndReturnError()
let report = try PLCrashReport(data: data)
guard let reportText = PLCrashReportTextFormatter .stringValue(for: report,with: PLCrashReportTextFormatiOS) else {
NSLog("crash rep 5 report text nil")
return
}
NSLog("crash rep 6 previous report: \(reportText)")
try crashReporter.purgePendingCrashReportAndReturnError()
NSLog("crash rep 7")
} catch {
NSLog("crash rep Error: \(error)")
}
}
NSLog("crash rep finished installation")
}
func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
setupCrashReporter()
return true
}
顺便说一句,这是我从中获得想法的官方存储库中的 objective-C demo file。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。