MetricKit and when or when not do we get reports?

75 views Asked by At

The MetricKit implementation is pretty straight forward. I am testing it now for a couple of days, but I never saw any report passed to my test apps. (implemented it in an empty app that just crashes every now and then and in a product of ours) The function 'didReceive' is never called and each time I am asking 'MXMetricManager.shared.pastDiagnosticPayloads' I get an empty collection.

So that is the secret here? Is MetricKit not working for development builds? Or are there other factors/requirements not meet?

import Foundation
import MetricKit

class CrashDetection: NSObject, MXMetricManagerSubscriber {
    @objc static let shared = CrashDetection()
    @objc private override init() { }

    internal static var crashDidOccur: Bool {
        get { UserDefaults.standard.bool(forKey: crashDidOccurKey) ?? false }
        set { UserDefaults.standard.set(newValue, forKey: crashDidOccurKey) }
    }

    @objc func start() {
        MXMetricManager.shared.add(self)
    }

    @objc func stop() {
        MXMetricManager.shared.remove(self)
    }

    func didReceive(_ payloads: [MXDiagnosticPayload]) {
        let crashDiagnostics = payloads.compactMap({ $0.crashDiagnostics })
        CrashDetection.crashDidOccur = crashDiagnostics.isEmpty == false
    }
}
0

There are 0 answers