问题描述
我正在尝试使用 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 (将#修改为@)