我试图用setCrashCallbacks快速调用setup setCrashCallbacks,但不知怎么的,回调显然没有被调用。我可以看到我所有的NSLog调用都出现在Console.app中。在下一次发布时,我还可以看到文本格式的报告。但是,我在回调中的NSLog调用从未在Console.app中显示。
我怎么能在斯威夫特做这件事?在斯威夫特能做到这一点吗?还是我要去-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演示文件,我从这里得到了一些想法。
发布于 2021-08-18 16:31:41
我找不到一种使用PLCrashReporter的好方法。经过几天的调查之后,我最终搬到了KSCrash,这是相当好的和高度可扩展的。
如果有人有PLCrashReported的解决方案,我会很高兴地给出答案的✅
import KSCrash_Installations
import KSCrash_Recording
KSCrash.sharedInstance().deleteBehaviorAfterSendAll = KSCDeleteNever
KSCrash.sharedInstance()?.maxReportCount = 1
// MyCrashInstallation could be any subclass of KSCrashInstallation
var installation: KSCrashInstallation? = MyCrashInstallation.shared
installation?.appleReportStyle = KSAppleReportStyleUnsymbolicated
installation?.install()
installation?.onCrash = { writer in
let userId:String = "example123"
let now = "20210831"
writer?.pointee.addStringElement(writer, "my_key_userid", "\(userId)")
writer?.pointee.addStringElement(writer, "my_error_date", "\(now)")
}https://stackoverflow.com/questions/67819590
复制相似问题